今天导出数据库到excel,碰到各种奇葩问题。最后找了个比较简单的方法,先全部查出来在复制粘贴一下是网上找的比较实用的sql 查询语句。
1 -- 查询非系统数据库
2 Select name FROM Master.. SysDatabases where dbid>4
3
4 -- 选择water数据库下的所有表
5 use [water] SELECT name FROM sysobjects WHERE xtype = 'U' Or xtype = 'S'
6
7 -- 选择water数据库下的所有用户表
8 use [water] SELECT name FROM sysobjects WHERE xtype = 'U' AND OBJECTPROPERTY (id, 'IsMSShipped') = 0
9
10 -- 查询water数据库下的admin表的字段名,长度,类型,字段说明
11 use [water] SELECT a.[name] as '字段名',a.length '长度',c.[name] '类型',e.value as '字段说明' FROM syscolumns a
12 left join systypes b on a.xusertype=b.xusertype
13 left join systypes c on a.xtype = c.xusertype
14 inner join sysobjects d on a.id=d.id and d.xtype='U'
15 left join sys.extended_properties e on a.id = e.major_id and a.colid = e.minor_id and e.name='MS_Description'
16 where d.name='admin'
以上查询语句可以结合下面的查找具体表的字段信息进行组合。
1 select * from information_schema.columns where table_name ='colocal'