資料庫結構比較的SQL 語句

2021-04-24 16:20:05 字數 2642 閱讀 7344

資料庫結構比較的sql 語句

sql server

chk_collist_mssql

select sysobjects.name + '.' +  syscolumns.name , systypes.name ,

syscolumns.length ,

case syscolumns.isnullable

when 1 then 'y'

when 0 then 'n'

end

from sysobjects , syscolumns ,systypes

where sysobjects.xtype ='u' and

sysobjects.id= syscolumns.id and

systypes.xtype = syscolumns.xtype

order by sysobjects.name ,  syscolumns.name ;

chk_cons_mssql

select distinct

convert(varchar(30),sysobjects_1.name) as table_name,

convert(varchar(30),syscolumns.name) as column_name,

sysindexkeys.keyno as position,

case sysobjects.xtype

when 'pk' then 'p'

when 'f' then 'r'

when 'c' then 'c'

when 'uq' then 'u'

when 'd' then 'c'

end  as constraint_type

from dbo.sysobjects inner join

dbo.sysobjects sysobjects_1 on

dbo.sysobjects.parent_obj = sysobjects_1.id inner join

dbo.syscolumns on sysobjects_1.id = dbo.syscolumns.id inner join

dbo.sysindexkeys on dbo.syscolumns.id = dbo.sysindexkeys.id and

dbo.syscolumns.colid = dbo.sysindexkeys.colid

where (sysobjects.xtype in ('c', 'f', 'pk', 'uq', 'd')) and

(sysobjects.status & 64 = 0) ;

chk_idx_collist_mssql

select dbo.sysindexes.name ,sysobjects.name + '.' +  syscolumns.name

from dbo.syscolumns inner join

dbo.sysindexkeys inner join

dbo.sysindexes on dbo.sysindexkeys.id = dbo.sysindexes.id on

dbo.syscolumns.colid = dbo.sysindexkeys.colid and

dbo.syscolumns.id = dbo.sysindexkeys.id inner join

dbo.sysobjects on dbo.sysindexes.id = dbo.sysobjects.id

where (dbo.sysobjects.xtype = 'u') and (dbo.sysindexes.indid > 0) and

(dbo.sysindexes.indid < 255)

order by dbo.sysobjects.name, dbo.syscolumns.name ;

oracle

chk_collist_oracle

select a.table_name||'.'||b.column_name,b.data_type,b.data_length,b.nullable

from user_tables a, user_tab_columns b

where a.table_name=b.table_name

order by a.table_name,b.column_name;

chk_cons_oracle

select distinct a.table_name,b.column_name,nvl(b.position,1) position,a.constraint_type

from user_constraints a,user_cons_columns b

where a.table_name=b.table_name and a.constraint_name=b.constraint_name

order by a.table_name,position;

chk_idx_collist_oracle

select index_name,table_name||'.'||column_name

from user_ind_columns

order by table_name,column_name;

以上是兩個一樣的資料庫進行差異比較用的sql

顯示資料庫中表結構的SQL語句

select case when a.colorder 1 then d.name else end n 表名 a.colorder n 字段序號 a.name n 欄位名 case when columnproperty a.id,a.name,isidentity 1 then else end...

資料庫 SQL語句

在sql語言中,我們可以通過create database去建立資料庫,語法格式如下所示 create database 資料庫名 就比如我們可以建立乙個學校資料庫 create database schooldb 建立表的操作 create table 表名稱 列名稱1 資料型別,列名稱2 資料型...

sql語句查詢資料庫表結構資訊

開發中經常用到查詢指定表及其欄位的資訊,以下是我整理的sql語句查詢方法,供自己平時使用也提供給大家參考!1.適用ms sql server 1 select 2 表名 case when a.colorder 1 then d.name else end,3 表說明 case when a.col...