SQL query table structure, process, view, primary key, foreign key, constraint

Source: Internet
Author: User

I. Table Structure Query

Select top (100) percent A. Name as zdm, columnproperty (A. ID, A. Name, 'isidentity ') as BS,
Case when exists (select 1 from DBO. sysindexes Si inner join DBO. sysindexkeys Sik ON Si. ID = Sik. ID
And Si. indid = Sik. indid inner join DBO. syscolumns SC on SC. ID = Sik. ID and SC. colid = Sik. colid
Inner join DBO. sysobjects so on so. Name = So. Name and so. xtype = 'pk' where SC. ID = A. ID and SC. colid = A. colid)
Then '1' else '0' end as ZJ, B. Name as lx, A. length as CD, columnproperty (A. ID, A. Name, 'precision ')
As JD, isnull (columnproperty (A. ID, A. Name, 'Scale'), 0) as xsws, A. isnullable as yxk, isnull (E. Text ,'')
As MRZ, isnull (G. Value, '') as zdsm from DBO. syscolumns as a left Outer Join DBO. policypes as B on A. xtype = B. xusertype
Inner join DBO. sysobjects as D on A. ID = D. id and D. xtype = 'U' and D. Status> = 0 left Outer Join
DBO. syscomments as E on A. cdefault = E. Id left Outer Join SYS. extended_properties as G
On a. ID = G. major_id and A. colid = G. minor_id left Outer Join SYS. extended_properties
As f on D. id = f. major_id and F. minor_id = 0 where D. Name = 'query table name'

 

II,
-- Query stored procedures
Select case. xtype when 'p' then' Stored Procedure 'end as lx,. name, B. text from sysobjects a left Outer Join syscomments B on. id = B. ID where xtype = 'P'
-- Query view
Select case. xtype when 'v'then' view 'end as lx,. name, B. text from sysobjects a left Outer Join syscomments B on. id = B. ID where xtype = 'V'

-- Primary key, foreign key, constraint
Select
Case A. xtype when 'pk' then' primary key 'when 'F' then' foreign key 'when 'C' then' constraint'
End as lx, A. Name as name,
B. Text from sysobjects a left Outer Join syscomments B on A. ID = B. ID
Where (A. xtype in ('C', 'F', 'pk') and
(Objectproperty (A. ID, N 'ismsshipped ') = 0) and A. parent_obj = (select ID from sysobjects where name = 'table _ 2 ')

 

 

The environment is sql2008

The names of the tables and views involved can be found in SQL help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.