在我们使用SQL数据库的过程中,经常会遇到查询表结构的情况,以下就是sql语句的写法:
--查询非系统数据库
SELECT name FROM Master..SysDatabases WHERE dbid > 4
查询数据库下所有表
SELECT name FROM sysobjects WHERE xtype = ‘U‘ OR xtype = ‘S‘
查询所有用户表
SELECT name FROM sysobjects WHERE xtype = ‘U‘ AND OBJECTPROPERTY(id, ‘IsMSShipped‘) = 0
查询表的相关信息(字段名、长度、类型、字段说明)
SELECT a.[name] AS ‘字段名‘ , a.length ‘长度‘ , c.[name] ‘类型‘ , e.value AS ‘字段说明‘ FROM syscolumns a LEFT JOIN systypes b ON a.xusertype = b.xusertype LEFT JOIN systypes c ON a.xtype = c.xusertype INNER JOIN sysobjects d ON a.id = d.id AND d.xtype = ‘U‘ LEFT JOIN sys.extended_properties e ON a.id = e.major_id AND a.colid = e.minor_id AND e.name = ‘MS_Description‘ WHERE d.name = ‘Comment‘
时间: 2024-10-10 13:00:10