SQL Server中查询所有数据库、所有表、字段的Sql语句
2007-08-01 09:38
936 查看
google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
当我们建立Sql Server 连接之后,可以通过如下语句得到当前Sql server中所有的数据的名称: google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
use master
select [name] from [sysdatabases] order by [name]
go
google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
执行后,结果如下:
name
--------------------------------------------------------------------------------------------------------------------------------
AspNetPager
ciw_sign
COMA_SAMSUNG
DJWorldProject
EmoAsp
iParkBJDatabase
iParkDB
jscp
master
model
msdb
MSPetShop
MSPetShopOrders
MYCLUB
Northwind
OnlinePro
pubs
SamSungShopAll
SoundEquipment
tempdb
TopWin
WeYyzyq
zt
(所影响的行数为 23 行)
google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
我们通过查询其中一个数据库aspnetpager,就可以得到这个数据库中的所有的表名了,语句如下:
use aspnetpager
select [id], [name] from [sysobjects] where [type] = 'u' order by [name]
google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
执行后的结果如下:
id name
----------- --------------------------------------------------------------------------------------------------------------------------------
629577281 BaseData
2137058649 dtproperties
2025058250 wqnews
(所影响的行数为 3 行)
google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
我们通过上面的查询的id,可以查出这个表中所有的字段,例如我们查询BaseData表中所有的字段,就可以通过下面的语句查出:
select [name] from [syscolumns] where [id] = 629577281 order by [colid]
go
google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
执行的结果如下:
name
--------------------------------------------------------------------------------------------------------------------------------
app_id
app_bscnm
app_shop_type
app_money
app_citylev
app_protype
app_type
SUBS_NM
AddDate
FinishDate
CheckDate
AsFinishDate
FromTable
(所影响的行数为 13 行)
通过表basedata所在[sysobjects]中对应的id“629577281”,可以得到该表中的记录条数。前提这个表中要建立索引,语句如下:
select [o].[id], [o].[name], [i].[rows] from [sysindexes] [i], [sysobjects] [o] where [i].[first]>0 and [o].[id]=[i].[id] and [o].[type]='u' and [o].[id]=629577281
执行的结果如下:
id name rows
----------- ------------------------------------------------------------------------- -----------
629577281 BaseData 11809
629577281 BaseData 11809
(所影响的行数为 2 行)
希望这些对于一些人有所帮助。当然重要的是留下来以供自己参考。
google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
当我们建立Sql Server 连接之后,可以通过如下语句得到当前Sql server中所有的数据的名称: google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
use master
select [name] from [sysdatabases] order by [name]
go
google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
执行后,结果如下:
name
--------------------------------------------------------------------------------------------------------------------------------
AspNetPager
ciw_sign
COMA_SAMSUNG
DJWorldProject
EmoAsp
iParkBJDatabase
iParkDB
jscp
master
model
msdb
MSPetShop
MSPetShopOrders
MYCLUB
Northwind
OnlinePro
pubs
SamSungShopAll
SoundEquipment
tempdb
TopWin
WeYyzyq
zt
(所影响的行数为 23 行)
google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
我们通过查询其中一个数据库aspnetpager,就可以得到这个数据库中的所有的表名了,语句如下:
use aspnetpager
select [id], [name] from [sysobjects] where [type] = 'u' order by [name]
google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
执行后的结果如下:
id name
----------- --------------------------------------------------------------------------------------------------------------------------------
629577281 BaseData
2137058649 dtproperties
2025058250 wqnews
(所影响的行数为 3 行)
google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
我们通过上面的查询的id,可以查出这个表中所有的字段,例如我们查询BaseData表中所有的字段,就可以通过下面的语句查出:
select [name] from [syscolumns] where [id] = 629577281 order by [colid]
go
google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
执行的结果如下:
name
--------------------------------------------------------------------------------------------------------------------------------
app_id
app_bscnm
app_shop_type
app_money
app_citylev
app_protype
app_type
SUBS_NM
AddDate
FinishDate
CheckDate
AsFinishDate
FromTable
(所影响的行数为 13 行)
通过表basedata所在[sysobjects]中对应的id“629577281”,可以得到该表中的记录条数。前提这个表中要建立索引,语句如下:
select [o].[id], [o].[name], [i].[rows] from [sysindexes] [i], [sysobjects] [o] where [i].[first]>0 and [o].[id]=[i].[id] and [o].[type]='u' and [o].[id]=629577281
执行的结果如下:
id name rows
----------- ------------------------------------------------------------------------- -----------
629577281 BaseData 11809
629577281 BaseData 11809
(所影响的行数为 2 行)
希望这些对于一些人有所帮助。当然重要的是留下来以供自己参考。
google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("");
相关文章推荐
- sql语句查询Oracle|sql server|access 数据库里的所有表名,字段名
- sql语句查询Oracle|sql server|access 数据库里的所有表名,字段名
- sql语句查询Oracle|sql server|access 数据库里的所有表名,字段名
- 查询当前数据库中所有有默认值的字段,并生成添加默认值的SQL语句
- mysql使用sql语句查询数据库所有表注释已经表字段注释
- Sql Server查看所有数据库名,表名,字段名(SQL语句)
- sql语句查询数据库里的所有表名,字段名
- sql语句查询 sql server access 数据库里的所有表名,字段名
- 查询数据库中所有表及所有字段的SQL语句
- SQL语句查询数据库所有表和所有字段的详细信息(包括表描述和字段描述)
- 从数据库中查询所有表及所有字段的SQL语句(转)
- sql查询数据库里所有表名,字段名的语句
- 从数据库中查询所有表及所有字段的SQL语句
- sql语句查询 sql server access 数据库里的所有表名,字段名
- SQL中利用sql语句查询数据库中的所有表、存储过程
- MySQL中查询所有数据库占用磁盘空间大小和单个库中所有表的大小的sql语句
- 用SQL语句查询数据库中某一字段下相同值的记录方法
- SQL Server查询数据库所有存储过程、触发器、索引信息SQL分享
- sql 查询所有数据库、表名、表字段总结
- SQL Server查询一个表的所有列名的SQL语句