SQL語句擷取所有資料庫名、表名、欄位名、表欄位長度

來源:互聯網
上載者:User

標籤:http   io   ar   for   資料   div   sp   on   c   

引自:http://www.2cto.com/database/201209/155178.htmlSQL語句擷取所有資料庫名、表名、欄位名、表欄位長度 擷取資料庫中所有的表SELECT SysObjects.name AS Tablename FROM sysobjects WHERE xtype = ‘U‘
 擷取資料庫中所有表的列名SELECT SysColumns.name AS Columnsname, SysObjects.name AS Tablename FROM SysObjects, SysColumns WHERE Sysobjects.Xtype=‘u‘ AND Sysobjects.Id=Syscolumns.Id  www.2cto.com  擷取SQL所有資料庫名、所有表名、所有欄位名、表欄位長度1.擷取MSSQL中的所有資料庫名:SELECT name FROM MASter..SysDatabASes ORDER BY name 2.擷取MSSQL中的所有使用者表名:SELECT name FROM DatabASename..SysObjects WHERE XType=‘U‘ ORDER BY nameXType=‘U‘:表示所有使用者表;XType=‘S‘:表示所有系統資料表; 3.擷取指定表[tb_phone]的所有欄位名:SELECT name FROM SysColumns WHERE id=Object_Id(‘tb_phone‘) 4.SQL所有表的表名、所有欄位名、表欄位長度SELECT table_name AS 資料表名,column_name AS 欄位名,ISNULL(column_default,‘‘) AS 預設值,is_nullable AS 是否允許為NULL, data_type AS 資料類型,ISNULL(ISNULL(ISNULL(character_maximum_length,numeric_precision),datetime_precision),1) AS 類型長度FROM information_schema.columnsWHERE NOT table_name IN(‘sysdiagrams‘,‘dtproperties‘) 5.擷取指定表[tb_phone]的表名,表欄位名,欄位類型和類型長度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.id = Syscolumns.id INNER JOINSystypes ON Syscolumns.xtype = Systypes.xtype ONSysproperties.id = Syscolumns.id AND Sysproperties.smallid = Syscolumns.colidWHERE (Sysobjects.xtype = ‘u‘ ORSysobjects.xtype = ‘v‘) AND (Systypes.name <> ‘Sysname‘) AND(Sysobjects.name = ‘tb_phone‘)ORDER BY Columnsname

SQL語句擷取所有資料庫名、表名、欄位名、表欄位長度

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.