Sqlcmd是sqlserver自帶的命令行工具,可以在不打開(kāi)企業(yè)管理器的時(shí)候訪問(wèn)本地或者遠(yuǎn)程的數(shù)據(jù)庫(kù),對(duì)數(shù)據(jù)庫(kù)進(jìn)行管理。
Sqlcmd連接數(shù)據(jù)庫(kù):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.查詢數(shù)據(jù)庫(kù)
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.查詢數(shù)據(jù)庫(kù)中的表
select name from sysobjects where xtype='U'
1> use master
2> go
已將數(shù)據(jù)庫(kù)上下文改為 '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 行受影響)
至于怎么打印出表字段的類(lèi)型這個(gè)可以連查systypes表。