--查看錶的屬性
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表(包括視圖、預存程序、函數)
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'
--查看與某一個表相關的視圖、預存程序、函數
select a.* from sysobjects a, syscomments b where a.id = b.id and b.text like '%表名%'
--查看當前資料庫中所有預存程序
select name as 預存程序名稱 from sysobjects where xtype='P'
--查詢某一個表的欄位和資料類型
select column_name,data_type from information_schema.columns
where table_name = '表名'
[n].[標題]:
Select * From TableName Order By CustomerName
其中xtype分別對應:
C = CHECK 條件約束
D = 預設值或 DEFAULT 約束
F = FOREIGN KEY 約束
FN = 純量涵式
IF = 內嵌表函數
K = PRIMARY KEY 或 UNIQUE 約束
L = 日誌
P = 預存程序
R = 規則
RF = 複製篩選預存程序
S = 系統資料表
TF = 表函數
TR = 觸發器
U = 使用者表
V = 視圖
X = 擴充預存程序