Heim >Datenbank >MySQL-Tutorial >Sqlserver2005 Sqlcmd查看数据库/表/字段的命令

Sqlserver2005 Sqlcmd查看数据库/表/字段的命令

WBOY
WBOYOriginal
2016-06-07 15:34:201284Durchsuche

Sqlcmd是sqlserver自带的命令行工具,可以在不打开企业管理器的时候访问本地或者远程的数据库,对数据库进行管理。 Sqlcmd连接数据库:sqlcmd -S 10.78.1.99 -U sa -P sa C:/Users/1232sqlcmd -S 10.78.1.99 -U sa -P sa 1 1.查询数据库 select name from ma

Sqlcmd是sqlserver自带的命令行工具,可以在不打开企业管理器的时候访问本地或者远程的数据库,对数据库进行管理。

Sqlcmd连接数据库:sqlcmd -S 10.78.1.99 -U sa -P sa

C:/Users/1232>sqlcmd -S 10.78.1.99 -U sa -P sa
1>

 

1.查询数据库
select name from master.dbo.sysdatabases

1> select name from master.dbo.sysdatabases
2> go
name
---------------------------------------------------------
master
tempdb
model
msdb
pubs
Northwind
COMMON_SECURITY
FlowEng
LTS
SUNDB
UTL
(11 行受影响)

 

2.查询数据库中的表
select name from sysobjects where xtype='U'

1> use master
2> go
已将数据库上下文改为 'master'。
1> select name from sysobjects where xtype='U'
2> go
name
------------------------------------------------------
spt_monitor
spt_values
spt_fallback_db
spt_fallback_dev
spt_fallback_usg
dtproperties
spt_provider_types
aofax_send_task
aofax_recv_task
FAXRECV
Pboc
spt_datatype_info_ext
MSreplication_options
spt_datatype_info
spt_server_info

(15 行受影响)


3.查询表中的列
select c.name,c.length from syscolumns c inner join sysobjects t on c.id = t.id and t.name='spt_monitor'

1> select c.name,c.length from syscolumns c inner join sysobjects t on c.id = t.id and t.name='spt_monitor'
2> go
name                                                                                                                             length
-------------------------------------------------------------------------------------------------------------------------------- ------
lastrun                                                                                                                               8
cpu_busy                                                                                                                              4
io_busy                                                                                                                               4
idle                                                                                                                                  4
pack_received                                                                                                                         4
pack_sent                                                                                                                             4
connections                                                                                                                           4
pack_errors                                                                                                                           4
total_read                                                                                                                            4
total_write                                                                                                                           4
total_errors                                                                                                                          4

(11 行受影响)

 

至于怎么打印出表字段的类型这个可以连查systypes表。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn