SQL Server query to get the list of column name in a table

Source: Internet
Author: User
Tags sql server query

--sql Server 2005, or 2012:select * from Information_schema.tables--sql server 2000:select * from sysobjects WHERE xt ype= ' 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 '-- The column names of all watches are shown in 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.us er_type_id = t.user_type_idleft OUTER JOIN sys.index_columns ic on ic.object_id = c.object_id and ic.column_id = C.col Umn_idleft OUTER JOIN sys.indexes i on ic.object_id = i.object_id and ic.index_id = i.index_idwhere c.object_id = O bject_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_SCH EMA. 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

Related Article

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.