1.獲取所有資料庫名:
select name from master..sysdatabases order by name
2.獲取所有表名:
select name from databasename..sysobjects where xtype='u' order by name
xtype='u':表示所有使用者表;
xtype='s':表示所有系統表;
3.獲取所有欄位名:
select name from syscolumns where id=object_id('tablename')
下面是獲取表名,大小,型別等
select
( case
when a.colorder=1
then d.
name
else
''end)表名, a.colorder 字段序號, a.
name 欄位名, (
case
when
columnproperty(a.id,a.
name,
'isidentity')=1
then
'√'else
''end) 標識, (
case
when (
select
count
(*)
from
sysobjects
where (
namein(
select
name
from
sysindexes
where (id = a.id)
and (indid
in(select indid
from
sysindexkeys
where (id = a.id)
and (colid
in(select colid
from
syscolumns
where (id = a.id)
and (
name = a.
name)))))))
and(xtype =
'pk'))>0
then
'√'else
''end) 主鍵, b.
name 型別, a.length 占用位元組數,
columnproperty(a.id,a.
name,
'precision')
as 長度,
isnull(
columnproperty(a.id,a.
name,
'scale'),0)
as 小數字數, (
case
when a.isnullable=1
then
'√'else
''end) 允許空,
isnull(e.
text,
'') 預設值,
isnull(g.[value],
'')
as 字段說明
from
syscolumns a
left
join
systypes b
on a.xtype=b.xusertype
inner
join
sysobjects d
on a.id=d.id
and d.xtype=
'u'and d.
name
<>
'dtproperties'
left
join
syscomments e
on a.cdefault=e.id
left
join
sysproperties g
on a.id=g.id
and a.colid = g.smallid
order
by a.id,a.colorder
列出MSSQL所有資料庫名 所有表名 所有欄位名
列出mssql所有資料庫名 所有表名 所有欄位名 1.獲取所有資料庫名 select name from master.sysdatabases order by name 2.獲取所有表名 select name from sysobjects where xtype u order by nam...
使用SQL查詢所有資料庫名和表名
show databases select table name from information schema.tables where table schema database name and table type base table select column name from inf...
使用SQL查詢所有資料庫名和表名
show databases select table name from information schema.tables where table schema database name andtable type base table select column name from info...