ORACLE 操作

来源:互联网 发布:海报自动设计软件 编辑:程序博客网 时间:2024/05/16 16:18
sqlplus用户:    scott/tiger    sys as sysdba 空密码转换用户登录:    connect 用户/密码    connect sys as sysdba   权限用户解锁:    alter user scott account unlock;-------------------------------------表: 创建表语法:    create table 表名    (        列名 类型 约束 是否为空,        ......        列名 类型 约束 是否为空    );查看表结构: desc 表名提交:commit;  修改命令:alter table    1、添加约束        alter table 表名 add constraint 约束名 约束类型    2、删除约束        alter table 表名 drop constraint 约束名    3、修改列        alter table 表名 modify(列名 类型 约束 是否为空)    4、添加列        alter table 表名 add(列名 类型 约束 是否为空)    5、删除列        alter table 表名 drop column 列名    6、修改列名        alter table 表名 rename column 列名 to 新列名    7、修改表名        alter table 表名 rename to 新表名。添加多行:    1、把源表中的数据添加到新表(已存在)        insert into 新表名(列名)        select 列名        from 源表名    2、把现有表中的数据创建到新表中(一定不能存在新表)      create table 新表 as selelct 列名 from 源表名 where (不要数据--where 1=2)--------------------------序列:    语法:        create sequence 序列名;    伪列:nextval,currval;        查看序列的当前值:select 序列名.currval from dual;        查看序列的下一个值:select 序列名.nextval from dual;修改:    alter sequence 序列名删除:    drop sequence 序列名--------------------------------------------创建用户:    create user 用户名 identified by 密码。1、分配会话权限(授权)    grant create session to 用户名。2、分配资源权限    grant resource to 用户名。  取消:    revoke resource from 用户名    grant命令用于为用户分配权限或角色,而revoke命令用于为用户撤销权限或角色---------------------访问其他用户的表。在其他用户登录的情况下授权:    grant select,insert,update,delete on 表名 to 用户名。查看用户的表:    select table_name from user_tables;--------------------伪列:    select rownum,表名.* from 表名 where rownum-----------------------------------清屏:clear scr;--------------------------D:\app\Myra\product\11.1.0\db_1\NETWORK\ADMIN   //D:\app\Myra\product\11.1.0\db_1\jdbc\lib    //jar包路径添加外键约束:    alter table 外键表 add constraint FK_名字 foreign key(外键列) references 主键表(列)
0 0