--查看表的屬性
select * from sysObjects where [Name] = 'section'
--用法
if exists ( select * from sysObjects where [Name] = 'section' and xtype='U' )
Drop Table table1
go
Create table1 ( )
--獲取所有用戶表
select Name from sysobjects where xtype='u' and status>=0
--查看表的字段
select * from sysColumns c where c.id=object_id('section')
select name from syscolumns where id=object_id('表名')
--查看用戶
select * From sysusers where status<>0
--查看誰引用了bbs_hits表(包括視圖、存儲過程、函數(shù))
Select distinct object_name(d.id) as 'program',
o.xtype
from sysdepends d inner join sysobjects o on d.id=o.id
where object_name(depid)='bbs_hits'
--查看與某一個表相關(guān)的視圖、存儲過程、函數(shù)
select a.* from sysobjects a, syscomments b where a.id = b.id and b.text like '%表名%'
--查看當前數(shù)據(jù)庫中所有存儲過程
select name as 存儲過程名稱 from sysobjects where xtype='P'
--查詢某一個表的字段和數(shù)據(jù)類型
select column_name,data_type from information_schema.columns
where table_name = '表名'
[n].[標題]:
Select * From TableName Order By CustomerName
其中xtype分別對應(yīng):
C = CHECK 約束
D = 默認值或 DEFAULT 約束
F = FOREIGN KEY 約束
FN = 標量函數(shù)
IF = 內(nèi)嵌表函數(shù)
K = PRIMARY KEY 或 UNIQUE 約束
L = 日志
P = 存儲過程
R = 規(guī)則
RF = 復(fù)制篩選存儲過程
S = 系統(tǒng)表
TF = 表函數(shù)
TR = 觸發(fā)器
U = 用戶表
V = 視圖
X = 擴展存儲過程