1. Get basic field attributes of the table
-- Obtain the table structure in sqlserver
Select Syscolumns. Name, policypes. Name, syscolumns. isnullable,
Syscolumns. Length
From Syscolumns, policypes
Where Syscolumns. xusertype = Policypes. xusertype
And Syscolumns. ID = Object_id ( ' Your table name ' )
Running Effect
2. If you want to obtain the description of a field
-- Obtain the primary key and description of the table structure in sqlserver.
Declare @ Table_name As Varchar ( Max )
Set @ Table_name = ' Your table name '
Select SYS. Columns. Name, SYS. types. Name, SYS. Columns. max_length, SYS. Columns. is_nullable,
( Select Count ( * ) From SYS. identity_columns Where SYS. identity_columns. Object_id = SYS. columns. Object_id And SYS. Columns. column_id = SYS. identity_columns.column_id) As Is_identity,
( Select Value From SYS. extended_properties Where SYS. extended_properties.major_id = SYS. columns. Object_id And SYS. extended_properties.minor_id = SYS. Columns. column_id) As Description
From SYS. columns, SYS. Tables, SYS. Types Where SYS. columns. Object_id = SYS. Tables. Object_id And SYS. Columns. system_type_id = SYS. types. system_type_id And SYS. Tables. Name = @ Table_name Order By SYS. Columns. column_id
Running Effect
3. Independently query incremental fields of the table
-- Separately query the incremental field of the table
Select [ Name ] From Syscolumns Where
ID = Object_id (N ' Your table name ' ) And Columnproperty (ID, name, ' Isidentity ' ) = 1
Running Effect
4. Obtain the table's primary and Foreign keys
-- Obtain the table's primary and foreign key constraints
Exec Sp_helpconstraint ' Your table name ' ;
Running Effect