- --sampledatatotestPostgresqlINFORMATION_SCHEMA
- --TABLETEST
- CREATETABLETEST(
- TEST_NAMECHAR(30)NOTNULL,
- TEST_IDINTEGERDEFAULT'0' TEST_DATETIMESTAMPNULL
- );
- ALTERTABLETESTADDCONSTRAINTPK_TESTPRIMARYKEY(TEST_ID);
- --TABLETEST2withsomeCONSTRAINTsandanINDEX
- TABLETEST2(
- IDINTEGER FIELD1INTEGER,248); line-height:18px"> FIELD2CHAR(15),248); line-height:18px"> FIELD3VARCHAR(50),248); line-height:18px"> FIELD4 FIELD5 ID2TABLETEST2CONSTRAINTPK_TEST2KEY(ID2);
- CONSTRAINTTEST2_FIELD1ID_IDXUNIQUE(ID,FIELD1);
- CONSTRAINTTEST2_FIELD4_IDXUNIQUE(FIELD4);
- INDEXTEST2_FIELD5_IDXONTEST2(FIELD5);
- --TABLENUMBERS
- TABLENUMBERS(
- NUMBER ENCHAR(100) FR--TABLENEWTABLE
- TABLENEWTABLE(
- INTDEFAULT0 SOMENAMEVARCHAR(12),248); line-height:18px"> SOMEDATETABLENEWTABLECONSTRAINTPKINDEX_IDXKEY(ID);
- SEQUENCENEWTABLE_SEQINCREMENT1START1;
- --VIEWonTEST
- VIEW"testview"(
- TEST_NAME,248); line-height:18px"> TEST_ID,248); line-height:18px"> TEST_DATE
- )AS
- SELECT*
- FROMTEST
- WHERETEST_NAMELIKE't%';
- --VIEWonNUMBERS
- VIEW"numbersview"(
- NUMBER,248); line-height:18px"> TRANS_EN,248); line-height:18px"> TRANS_FR
- FROMNUMBERS
- WHERENUMBER>100;
- --TRIGGERonNEWTABLE
- FUNCTIONadd_stamp()RETURNSOPAQUEAS'
- BEGIN
- IF(NEW.somedateISNULLORNEW.somedate=0)THEN
- NEW.somedate:=CURRENT_TIMESTAMP;
- RETURNNEW;
- ENDIF;
- END;
- 'LANGUAGE'plpgsql';
- TRIGGERADDCURRENTDATE
- BEFOREINSERTORUPDATE
- ONnewtableFOREACHROW
- EXECUTEPROCEDUREadd_stamp();
- --TABLEsfortestingCONSTRAINTs
- TABLEtestconstraints(
- someidinteger somenamecharactervarying(10)CONSTRAINTtestconstraints_id_pkKEY(someid)
- TABLEtestconstraints2(
- ext_id modifieddate,248); line-height:18px"> uniquefield usractionCONSTRAINTtestconstraints_id_fkFOREIGNKEY(ext_id)
- REFERENCEStestconstraints(someid)MATCHSIMPLE
- ONUPDATECASCADEDELETECASCADE,153); background-color:inherit; font-weight:bold">CONSTRAINTunique_2_fields_idxUNIQUE(modified,usraction),153); background-color:inherit; font-weight:bold">CONSTRAINTuniquefld_idxUNIQUE(uniquefield)
- );
- --TABLETEST
- CREATETABLETEST(
- TEST_NAMECHAR(30)NOTNULL,
- TEST_IDINTEGERDEFAULT'0' TEST_DATETIMESTAMPNULL
- );
- ALTERTABLETESTADDCONSTRAINTPK_TESTPRIMARYKEY(TEST_ID);
- --TABLETEST2withsomeCONSTRAINTsandanINDEX
- TABLETEST2(
- IDINTEGER FIELD1INTEGER,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> FIELD2CHAR(15),248); line-height:18px"> FIELD3VARCHAR(50),108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> FIELD4 FIELD5 ID2TABLETEST2CONSTRAINTPK_TEST2KEY(ID2);
- CONSTRAINTTEST2_FIELD1ID_IDXUNIQUE(ID,FIELD1);
- CONSTRAINTTEST2_FIELD4_IDXUNIQUE(FIELD4);
- INDEXTEST2_FIELD5_IDXONTEST2(FIELD5);
- --TABLENUMBERS
- TABLENUMBERS(
- NUMBER ENCHAR(100) FRNULL
- );
- --TABLENEWTABLE
- TABLENEWTABLE(
- INTDEFAULT0 SOMENAMEVARCHAR(12),108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> SOMEDATETABLENEWTABLECONSTRAINTPKINDEX_IDXKEY(ID);
- SEQUENCENEWTABLE_SEQINCREMENT1START1;
- --VIEWonTEST
- VIEW"testview"(
- TEST_ID,248); line-height:18px"> TEST_DATE
- )AS
- SELECT*
- FROMTEST
- WHERETEST_NAMELIKE't%';
- --VIEWonNUMBERS
- VIEW"numbersview"(
- TRANS_EN,248); line-height:18px"> TRANS_FR
- FROMNUMBERS
- WHERENUMBER>100;
- --TRIGGERonNEWTABLE
- FUNCTIONadd_stamp()RETURNSOPAQUEAS'
- BEGIN
- IF(NEW.somedateISNULLORNEW.somedate=0)THEN
- NEW.somedate:=CURRENT_TIMESTAMP;
- RETURNNEW;
- ENDIF;
- END;
- 'LANGUAGE'plpgsql';
- TRIGGERADDCURRENTDATE
- BEFOREINSERTORUPDATE
- ONnewtableFOREACHROW
- EXECUTEPROCEDUREadd_stamp();
- --TABLEsfortestingCONSTRAINTs
- TABLEtestconstraints(
- someidinteger somenamecharactervarying(10)CONSTRAINTtestconstraints_id_pkKEY(someid)
- TABLEtestconstraints2(
- ext_id modifieddate,248); line-height:18px"> uniquefield usractionCONSTRAINTtestconstraints_id_fkFOREIGNKEY(ext_id)
- REFERENCEStestconstraints(someid)MATCHSIMPLE
- ONUPDATECASCADEDELETECASCADE,153); background-color:inherit; font-weight:bold">CONSTRAINTunique_2_fields_idxUNIQUE(modified,153); background-color:inherit; font-weight:bold">CONSTRAINTuniquefld_idxUNIQUE(uniquefield)
- );
列出所有数据库中的表名
- FROMpg_class
- WHERErelname!~'^(pg_|sql_)'
- ANDrelkind='r';
- <!--
- SELECTc.relnameAS"Name"
- FROMpg_classc,pg_useru
- WHEREc.relowner=u.usesysid
- ANDc.relkind='r'
- ANDNOTEXISTS(
- SELECT1
- FROMpg_views
- WHEREviewname=c.relname
- )
- ANDc.relname!~'^(pg_|sql_)'
- UNION
- FROMpg_classc
- WHEREc.relkind='r'
- FROMpg_user
- WHEREusesysid=c.relowner
- ANDc.relname!~'^pg_';
- -->
- --usingINFORMATION_SCHEMA:
- SELECTtable_name
- FROMinformation_schema.tables
- WHEREtable_type='BASETABLE'
- ANDtable_schemaIN
- ('pg_catalog','information_schema');
copy