首页 > 代码库 > sql server query to get the list of column name in a table
sql server query to get the list of column name in a table
--SQL Server 2005, 2008 or 2012:SELECT * FROM information_schema.tables--SQL Server 2000:SELECT * FROM sysobjects WHERE xtype=‘U‘ SELECT * FROM sysobjects WHERE xtype=‘U‘ SELECT TABLE_NAME FROM geovidnu.INFORMATION_SCHEMA.TablesSELECT sobjects.nameFROM sysobjects sobjectsWHERE sobjects.xtype = ‘U‘EXEC sp_spaceused ‘YourTableName‘--顯示所有錶的列名SELECT COLUMN_NAME,TABLE_NAME FROM geovidnu.INFORMATION_SCHEMA.COLUMNSSELECT * FROM geovidnu.INFORMATION_SCHEMA.COLUMNSSELECT c.name ‘Column Name‘, t.Name ‘Data type‘, c.max_length ‘Max Length‘, c.precision , c.scale , c.is_nullable, ISNULL(i.is_primary_key, 0) ‘Primary Key‘FROM sys.columns cINNER JOIN sys.types t ON c.user_type_id = t.user_type_idLEFT OUTER JOIN sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_idLEFT OUTER JOIN sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_idWHERE c.object_id = OBJECT_ID(‘YourTableName‘)--http://stackoverflow.com/questions/2418527/sql-server-query-to-get-the-list-of-columns-in-a-table-along-with-data-types-noselect COLUMN_NAME,DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, DATETIME_PRECISION, IS_NULLABLE from INFORMATION_SCHEMA.COLUMNSwhere TABLE_NAME=‘YourTableName‘Select C.COLUMN_NAME, C.DATA_TYPE, C.CHARACTER_MAXIMUM_LENGTH, C.NUMERIC_PRECISION, C.IS_NULLABLE, TC.CONSTRAINT_NAMEFrom INFORMATION_SCHEMA.COLUMNS As C Left Join INFORMATION_SCHEMA.TABLE_CONSTRAINTS As TC On TC.TABLE_SCHEMA = C.TABLE_SCHEMA And TC.TABLE_NAME = C.TABLE_NAME And TC.CONSTRAINT_TYPE = ‘PRIMARY KEY‘Where C.TABLE_NAME = ‘YourTableName‘----http://sqlserver2000.databases.aspfaq.com/how-do-i-get-a-list-of-sql-server-tables-and-their-row-counts.html
sql server query to get the list of column name in a table
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。