Get the table for the database
SELECTobj.name tablename,schem.name Schemname,CAST( Case when(SELECT COUNT(1) fromSys.indexesWHERE object_id=Obj.object_id andIs_primary_key=1)>=1 Then 1 ELSE 0 END as BIT) HasPrimaryKey fromsys.objects objInner JoinDbo.sysindexes IDX onObj.object_id=Idx.id andIdx.indid<=1INNER JOINSys.schemas Schem onobj.schema_id=schem.schema_idwhereType='U' andObj.name='Table name'Order byObj.name
Gets the field name and type of the table
1, Method one
SELECT * from Information_schema.columns WHERE table_name= ' table name '
2. Method Two
Select A.name tablename, B.name colname, C.name coltype, C.length collength
From sysobjects a inner join syscolumns b
On a.id=b.id and a.xtype= ' U '
INNER JOIN systypes C
On B.xtype=c.xusertype
Where a.name= ' table name '
Law:
Table information is stored in: sys.objects
Schema information in: Sys.schemas
Index information in: sys.indexes
Column information in: sys.columns
These four are all views.
How SQL Server obtains information