Thứ Hai, 23 tháng 7, 2012

Xem danh sách các object trong Database SQL Server

Truy vấn thông tin trong sys.objects để xem thông tin các object được tạo trong database. Những thông tin này rất có ích trong việc quản lý database.
  1. select * from sys.objects  
  2.       
Chúng ta có thể filter các object dựa vào type của chúng. Ví dụ bạn muốn lấy danh sách tất cả các table trong database:
  1. -- type='u' tức là table  
  2. select * from sys.objects where type='u'  
  3. -- tương đương với:  
  4. select * from sys.tables  
  5.       
Hoặc danh sách tất cả các stored procedure:
  1. select * from sys.objects where type='p'  
  2. -- tương đương với:  
  3. select * from sys.procedures  
  4.       
Danh sách type của các object tham khảo từ MSDN:
Object type:
AF = Aggregate function (CLR)
C = CHECK constraint
D = DEFAULT (constraint or stand-alone)
F = FOREIGN KEY constraint
FN = SQL scalar function
FS = Assembly (CLR) scalar-function
FT = Assembly (CLR) table-valued function
IF = SQL inline table-valued function
IT = Internal table
P = SQL Stored Procedure
PC = Assembly (CLR) stored-procedure
PG = Plan guide
PK = PRIMARY KEY constraint
R = Rule (old-style, stand-alone)
RF = Replication-filter-procedure
S = System base table
SN = Synonym
SO = Sequence object
SQ = Service queue
TA = Assembly (CLR) DML trigger
TF = SQL table-valued-function
TR = SQL DML trigger
TT = Table type
U = Table (user-defined)
UQ = UNIQUE constraint
V = View
X = Extended stored procedure
Nguồn MSDN

Không có nhận xét nào :

Đăng nhận xét