1.創建用戶、賦許可權、刪除用戶 2.修改用戶密碼&解除鎖定(需要DBA許可權) 3.查詢鎖表 4.左右連接去除笛卡爾積 5.增加新的主鍵約束 6.級聯刪除外鍵(刪除父表記錄時,同時刪除子表記錄) 7.修改表名(表名大小寫問題) 8.將本用戶下全部sequence查詢出來,並拼成創建語句 常用sql待續 ...
1.創建用戶、賦許可權、刪除用戶
create user test identified by test default test users temporary tablespace temp; grant connect to test ; grant resource to test ; grant dba to test ; drop user test cascade;
2.修改用戶密碼&解除鎖定(需要DBA許可權)
alter user SCOTT identified by tiger; alter user SCOTT account unlock;
3.查詢鎖表
SELECT'alter system kill session '''|| c.sid ||''||','|| c.serial# ||''';', a.object_id, a.session_id, b.object_name, c.* FROM v$locked_object a, dba_objects b, v$session c WHERE a.object_id = b.object_id AND a.SESSION_ID = c.sid(+) AND schemaname ='SCOTT' ORDER BY logon_time
4.左右連接去除笛卡爾積
關於左連接和右連接總結性的一句話: 左連接where隻影向右表,右連接where隻影響左表。 Left Join select * from tbl1 Left Join tbl2 where tbl1.ID = tbl2.ID 左連接後的檢索結果是顯示tbl1的所有數據和tbl2中滿足where 條件的數據。
5.增加新的主鍵約束
alter table 表名 add constraint 主鍵名 primary key(欄位名); alter table DEPT add constraint PK_DEPT primary key(DEPTNO, DNAME);
6.級聯刪除外鍵(刪除父表記錄時,同時刪除子表記錄)
ALTER TABLE 子表 ADD CONSTRAINT FK_ACTIVITY_ID FOREIGN KEY (ID) REFERENCES 父表 (ID) ON DELETE CASCADE;
7.修改表名(表名大小寫問題)
ALTER TABLE "DEPT" RENAME TO DEPT;
8.將本用戶下全部sequence查詢出來,並拼成創建語句
select 'create sequence '||sequence_name|| ' minvalue '||min_value|| ' maxvalue '||max_value|| ' start with '||last_number|| ' increment by '||increment_by|| (case when cache_size=0 then ' nocache' else ' cache '||cache_size end) ||';' from user_sequences
常用sql待續,歡迎留言補充