(资料图片)
insert into dept_east (deptno,dname,loc) select deptno,dname,loc from dept where loc in ( "NEW YORK","BOSTON" )
create table dept_2 as select * from dept where 1 = 0
select * into dept_2 from dept where 1 = 0
delete from emp where not exists ( select * from dept where dept.deptno = emp.deptno)
create table dupes (id integer, name varchar(10))insert into dupes values (1, "NAPOLEON")insert into dupes values (2, "DYNAMITE")insert into dupes values (3, "DYNAMITE")insert into dupes values (4, "SHE SELLS")insert into dupes values (5, "SEA SHELLS")insert into dupes values (6, "SEA SHELLS")insert into dupes values (7, "SEA SHELLS")select * from dupes order by 1
select min(id) from dupes group by name
delete from dupes where id not in ( select min(id) from dupes group by name )
create table dept_accidents( deptno integer, accident_name varchar(20) )insert into dept_accidents values (10,"BROKEN FOOT")insert into dept_accidents values (10,"FLESH WOUND")insert into dept_accidents values (20,"FIRE")insert into dept_accidents values (20,"FIRE")insert into dept_accidents values (20,"FLOOD")insert into dept_accidents values (30,"BRUISED GLUTE")select * from dept_accidents
select deptno from dept_accidents group by deptnohaving count(*) >= 3
delete from emp where deptno in ( select deptno from dept_accidents group by deptno having count(*) >= 3 )
select table_name from information_schema.tables where table_schema = "SMEAGOL"
select table_name from all_tables where owner = "SMEAGOL"
select tabname from syscat.tables where tabschema = "SMEAGOL"
select column_name, data_type, ordinal_position from information_schema.columns where table_schema = "SMEAGOL" and table_name = "EMP"
select column_name, data_type, column_id from all_tab_columns where owner = "SMEAGOL" and table_name = "EMP"
select colname, typename, colno from syscat.columns where tabname = "EMP" and tabschema = "SMEAGOL"
select a.tablename,a.indexname,b.column_name from pg_catalog.pg_indexes a, information_schema.columns b where a.schemaname = "SMEAGOL" and a.tablename = b.table_name
select table_name, index_name, column_name, column_position from sys.all_ind_columns where table_name = "EMP" and table_owner = "SMEAGOL"
select a.name table_name, b.name index_name, d.name column_name, c.index_column_id from sys.tables a, sys.indexes b, sys.index_columns c, sys.columns d. where a.object_id = b.object_id and b.object_id = c.object_id and b.index_id = c.index_id and c.object_id = d.object_id and c.column_id = d.column_id and a.name = "EMP"
select a.tabname, b.indname, b.colname, b.colseq from syscat.indexes a, syscat.indexcoluse b where a.tabname = "EMP" and a.tabschema = "SMEAGOL" and a.indschema = b.indschema and a.indname = b.indname
select a.table_name, a.constraint_name, b.column_name, a.constraint_type from information_schema.table_constraints a, information_schema.key_column_usage b where a.table_name = "EMP" and a.table_schem = "SMEAGOL" and a.table_name = b.table_name and a.table_schema = b.table_schema and a.constraint_name = b.constraint_name
select a.table_name, a.constraint_name, b.column_name, a.constraint_type from all_constraints a, all_cons_columns b where a.table_name = "EMP" and a.owner = "SMEAGOL" and a.table_name = b.table_name and a.owner = b.owner and a.constraint_name = b.constraint_name
select a.tabname, a.constname, b.colname, a.type from syscat.tabconst a, syscat.columns b where a.tabname = "EMP" and a.tabschema = "SMEAGOL" and a.tabname = b.tabname and a.tabschema = b.tabschema
select fkeys.table_name, fkeys.constraint_name, fkeys.column_name, ind_cols.indexname from ( select a.constraint_schema, a.table_name, a.constraint_name, a.column_name from information_schema.key_column_usage a, information_schema.referential_constraints b where a.constraint_name = b.constraint_name and a.constraint_schema = b.constraint_schema and a.constraint_schema = "SMEAGOL" and a.table_name = "EMP" ) fkeys left join ( select a.schemaname, a.tablename, a.indexname, b.column_name from pg_catalog.pg_indexes a, information_schema.columns b where a.tablename = b.table_name and a.schemaname = b.table_schema ) ind_cols on ( fkeys.constraint_schema = ind_cols.schemaname and fkeys.table_name = ind_cols.tablename and fkeys.column_name = ind_cols.column_name ) where ind_cols.indexname is null
select a.table_name, a.constraint_name, a.column_name, c.index_name from all_cons_columns a, all_constraints b, all_ind_columns c where a.table_name = "EMP" and a.owner = "SMEAGOL" and b.constraint_type = "R" and a.owner = b.owner and a.table_name = b.table_name and a.constraint_name = b.constraint_name and a.owner = c.table_owner (+) and a.table_name = c.table_name (+) and a.column_name = c.column_name (+) and c.index_name is null
select fkeys.table_name, fkeys.constraint_name, fkeys.column_name, ind_cols.index_name from ( select a.object_id, d.column_id, a.name table_name, b.name constraint_name, d.name column_name from sys.tables a join sys.foreign_keys b on ( a.name = "EMP" and a.object_id = b.parent_object_id ) join sys.foreign_key_columns c on ( b.object_id = c.constraint_object_id ) join sys.columns d on ( c.constraint_column_id = d.column_id and a.object_id = d.object_id ) ) fkeys left join ( select a.name index_name, b.object_id, b.column_id from sys.indexes a, sys.index_columns b where a.index_id = b.index_id ) ind_cols on ( fkeys.object_id = ind_cols.object_id and fkeys.column_id = ind_cols.column_id ) where ind_cols.index_name is null
select fkeys.tabname, fkeys.constname, fkeys.colname, ind_cols.indname from ( select a.tabschema, a.tabname, a.constname, b.colname from syscat.tabconst a, syscat.keycoluse b where a.tabname = "EMP" and a.tabschema = "SMEAGOL" and a.type = "F" and a.tabname = b.tabname and a.tabschema = b.tabschema ) fkeys left join ( select a.tabschema, a.tabname, a.indname, b.colname from syscat.indexes a, syscat.indexcoluse b where a.indschema = b.indschema and a.indname = b.indname ) ind_cols on ( fkeys.tabschema = ind_cols.tabschema and fkeys.tabname = ind_cols.tabname and fkeys.colname = ind_cols.colname ) where ind_cols.indname is null
select "select count(*) from "||table_name||";" cnts from user_tables;CNTS--------------------------------------select count(*) from ANT;select count(*) from BONUS;select count(*) from DEMO1;select count(*) from DEMO2;select count(*) from DEPT;select count(*) from DUMMY;
select "alter table "||table_name|| " disable constraint "||constraint_name||";" cons from user_constraints where constraint_type = "R";CONS--------------------------------------------------------alter table ANT disable constraint ANT_FK;alter table BONUS disable constraint BONUS_FK;alter table DEMO1 disable constraint DEMO1_FK;alter table DEMO2 disable constraint DEMO2_FK;alter table DEPT disable constraint DEPT_FK;alter table DUMMY disable constraint DUMMY_FK;
select "insert into emp(empno,ename,hiredate) "||chr(10)|| "values( "||empno||","||""""||ename ||""",to_date("||""""||hiredate||""") );" inserts from empwhere deptno = 10;INSERTS---------------------------------------------------------------insert into emp(empno,ename,hiredate)values( 7782,"CLARK",to_date("09-JUN-1981 00:00:00") );insert into emp(empno,ename,hiredate)values( 7839,"KING",to_date("17-NOV-1981 00:00:00") );insert into emp(empno,ename,hiredate)values( 7934,"MILLER",to_date("23-JAN-1982 00:00:00") );
关键词:
Copyright 2000-2021 by www.jiaoyu.rexun.cn all rights reserved
邮箱 : 5 146 761 13 @qq.com