標籤:
一 系統管理使用者1 查詢使用者集合select username from dba_users;A 查詢某個使用者是否存在select username from dba_users where username=‘使用者名稱‘2 查詢使用者權限select * from dba_sys_privs where grantee=‘使用者名稱‘3 建立使用者create user 使用者名稱 identified by 密碼;4 刪除使用者drop user wp cascade;5 切換使用者A conn / as sysdba //切換管理員b conn 使用者名稱/密碼 //切換普通使用者6 細分授予許可權A grant create session to wp;//授權登入許可權B grant unlimited tablespace to wp;//授予zhangsan使用者使用資料表空間的許可權C grant create table to wp;//授予建立表的許可權D grante drop any table to wp;//授予刪除表的許可權E grant create sequence,select any sequence to 使用者//授予 使用者查詢和建立序列的許可權7 給使用者授予全部許可權A grant create session, create any table, create any view ,create any index, create any procedure, alter any table, alter any procedure, drop any table, drop any view, drop any index, drop any procedure, select any table, insert any table, update any table, delete any table to wp;B grant all to wp; 8 使用者之間表訪問的許可權授予A grant select on tablename to zhangsan;//授予zhangsan使用者查看指定表的許可權B grant drop on tablename to zhangsan;//授予刪除表的許可權C grant insert on tablename to zhangsan;//授予插入的許可權D grant update on tablename to zhangsan;//授予修改表的許可權E grant insert(id) on tablename to zhangsan;F grant update(id) on tablename to zhangsan;//授予對指定表特定欄位的插入和修改許可權,注意,只能是insert和updateG grant alert all table to zhangsan;//授予zhangsan使用者alert任意表的許可權9 取消使用者權限A revoke delete any table from wp;//取消使用者刪除許可權,其他於此類似B revoke create session, create any table, create any view ,create any index, create any procedure, alter any table, alter any procedure, drop any table, drop any view, drop any index, drop any procedure, select any table, insert any table, update any table, delete any table from wp; 二 管理表 1 建立表 create table 表名; A 主鍵 primary key C 設定約束 constraint 2 刪除表 drop table 表名 3 修改表名 rename 原表名 to 新表名 4 查詢表結構 DESC 表名 5 清除表資料 delete from 表名6 清空刪除表 PURGE recyclebin; 7 徹底刪除表drop table 表名 purge 三 欄位操作 1 增加欄位 A 增加單欄位 alter table 表名 add 欄位名 資料類型; B 增加多欄位 alter table demo1 add(欄位名 資料類型, ......依此類推); 2 刪除欄位 alter table 表名 drop column 欄位名; 3 修改欄位名稱 ALTER TABLE 表名 RENAME COLUMN 舊欄位名 TO 新欄位名; 4 修改欄位類型 ALTER TABLE 表名 MODIFY 欄位名 新欄位類型; 四 注釋 1 查詢表注釋select comments from user_tab_comments where table_name=‘表名‘;//需要注意的是表名需要大寫,相應的還有dba_tab_comments,all_tab_comments,這兩個比user_tab_comments多了ower列。 2 增加表注釋 comment on table demo1 is 注釋; 3 查詢表欄位注釋 SELECT TABLE_NAME,COLUMN_NAME,COMMENTS FROM USER_COL_COMMENTS WHERE TABLE_NAME = ‘表名‘;//需要注意的是表名需要大寫 4 增加欄位注釋 comment on column 表名.列名 is ‘注釋‘; 五 序列 1 查詢使用者序列 select sequence_name,sequence_owner from ALL_SEQUENCES where sequence_owner=‘使用者名稱‘;//注意使用者名稱得大寫 2 增加序列 create sequence demo1_seq minvalue 最小值 maxvalue 最大值 start with 1 increment by 1 cache 10; 3 查詢序列select * from ALL_SEQUENCES where sequence_name=‘序列名‘;//注意序列名需要大寫 4 刪除序列 drop sequence DEMO1_SEQ;5 或許序列值序列名.nextval六 觸發器1 查詢觸發器2 增加觸發器3 刪除觸發器
Oracle 常用命令