How can i learn Table Name in database an column name?
How can i learn table Name in database an how can i learn any Table's Column name?
SELECT Col.COLUMN_NAME, Col.DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS AS Col
LEFT OUTER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS Usg ON Col.TABLE_NAME = Usg.TABLE_NAME AND Col.COLUMN_NAME = Usg.COLUMN_NAME
LEFT OUTER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS Con ON Usg.CONSTR开发者_高级运维AINT_NAME = Con.CONSTRAINT_NAME
WHERE Col.TABLE_NAME = 'Addresses_Temp' AND Con.Constraint_TYPE = 'PRIMARY KEY'
But it returns to me empty data:(
I'm not entirely sure what the question is but here it goes anyway....
Displays Table information
Select * From Information_Schema.Tables
Displays Column information
Select * From Information_Schema.Columns
Displays Table Constraint information
Select * From Information_Schema.Table_Constraints
Here is some further resources relating to the Information Schema views.
http://msdn.microsoft.com/en-us/library/ms186778.aspx
If your query returns no rows then maybe the table doesn't exist anymore. It is named _temp
after all
Your query structure must be below
SELECT * from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='SchemaName' AND TABLE_NAME='TableName'
for example:
SELECT * from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='dbo' AND TABLE_NAME='Category'
精彩评论