SQL statement gets all database names, table names, field names, table fields length

Source: Internet
Author: User
Tags mssql

Citation: Http://www.2cto.com/database/201209/155178.htmlSQL statement gets all database names, table names, field names, table fields length gets all the tables in the database select Sysobjects.name as Tablename from sysobjects WHERE xtype = ' U '
  Get column names for all tables in the database select Syscolumns.name as Columnsname, sysobjects.name as Tablename from SysObjects, syscolumns WHERE S Ysobjects. Xtype= ' u ' and sysobjects.id=syscolumns.id  www.2cto.com   get SQL all database names, all table names, all field names, table field lengths 1. Get all database names in MSSQL: SELECT name from MASter. sysdatabases ORDER by name 2. Gets all user table names in MSSQL: SELECT name from DatabASename. SysObjects WHERE xtype= ' u ' ORDER by namextype= ' U ': represents all user tables; Xtype= ' S ': represents all system tables;  3. Gets all field names for the specified table [Tb_phone]: SELECT name from syscolumns WHERE id=object_id (' Tb_phone ')  4. Table name of all SQL tables, all field names, table field lengths select TABLE_NAME as data table name, column_name as field name, ISNULL (Column_default, ") as default, is_nullable as is allowed for Null, data_type as data type, ISNULL (ISNULL (ISNULL (character_maximum_length,numeric_precision), datetime_ Precision), 1) as type length from Information_schema.columnswhere not table_name in (' Sysdiagrams ', ' dtproperties ')  5. Gets the table name of the specified table [Tb_phone], the field type and the type length of the name, select Sysobjects.name as tablename,syscolumns.name as columnsname,systypes.name as Datetype,syscolumns.length As datelength  www.2cto.com  from sysproperties right OUTER joinsysobjects INNER joinsyscolumns on sysobjects.i D = syscolumns.id INNER joinsystypes on syscolumns.xtype = Systypes.xtype onsysproperties.id = syscolumns.id AND&NBSP;SYSP Roperties.smallid = syscolumns.colidwhere (Sysobjects.xtype = ' u ' orsysobjects.xtype = ' V ') and (Systypes.name <> ' S Ysname ') and (sysobjects.name = ' tb_phone ') ORDER by Columnsname

SQL statement gets all database names, table names, field names, table fields length

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.