如果需要查询表结构,SQL语句能否实现呢?下面就将为您介绍查询表结构的​​SQL​​语句的写法,希望对您学习SQL语句能够有所帮助。


  1. -- 查询非系统数据库
  2. Select name FROM Master.. SysDatabases where dbid>4

  3. -- 选择water数据库下的所有表
  4. use [water] SELECT name FROM sysobjects WHERE xtype = 'U' Or xtype = 'S'

  5. -- 选择water数据库下的所有用户表
  6. use [water] SELECT name FROM sysobjects WHERE xtype = 'U' AND OBJECTPROPERTY (id, 'IsMSShipped') = 0

  7. -- 查询water数据库下的admin表的字段名,长度,类型,字段说明
  8. use [water] SELECT a.[name] as '字段名',a.length '长度',c.[name] '类型',e.value as '字段说明' FROM syscolumns a
  9. left join systypes b on a.xusertype=b.xusertype
  10. left join systypes c on a.xtype = c.xusertype
  11. inner join sysobjects d on a.id=d.id and d.xtype='U'
  12. left join sys.extended_properties e on a.id = e.major_id and a.colid = e.minor_id and e.name='MS_Description'
  13. where d.name='admin'