Oracle基本命令大全

 用戶:  session

scott/tiger  ide

sys as sysdba 空密碼spa

轉換用戶登陸:  資源

connect 用戶/密碼  it

connect sys as sysdba   權限io

用戶解鎖:table

 alter user scott account unlock;登錄

-------------------------------------date

表:  select

建立表語法:

 create table 表名  (   列名 類型 約束 是否爲空,   ......   列名 類型 約束 是否爲空  );

查看錶結構:

desc 表名

提交:

commit;  

修改命令:

alter table  

一、添加約束   

alter table 表名 add constraint 約束名 約束類型  

二、刪除約束   

alter table 表名 drop constraint 約束名  

三、修改列   

alter table 表名 modify(列名 類型 約束 是否爲空)  

四、添加列   

alter table 表名 add(列名 類型 約束 是否爲空)  

五、刪除列   

alter table 表名 drop column 列名  

六、修改列名   

alter table 表名 rename column 列名 to 新列名  

七、修改表名  

 alter table 表名 rename to 新表名。

添加多行:  

一、把源表中的數據添加到新表(已存在)   insert into 新表名(列名)   select 列名   from 源表名  

二、把現有表中的數據建立到新表中(必定不能存在新表)    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 密碼。

一、分配會話權限(受權)  grant create session to 用戶名。

二、分配資源權限  grant connect,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;

--------------------------

添加外鍵約束:

alter table 外鍵表 add constraint FK_名字 foreign key(外鍵列) references 主鍵表(列)  

alter table 外間表 add constraint fk_名字 foreign key (外鍵列) references 主鍵表(列)

相關文章
相關標籤/搜索