Sql Server语句 --查询数据库指定表的大小 EXEC sp_spaceused 'SMSHistory' --查询数据库中一共有多少个表 select count(*) 总表数 from sysobjects where xtype='u' --将需要备份的数据库某个表数据备份到指定的数据库 --启用Ad Hoc Distributed Queries --EXEC sp_configure 'show advanced options',1 reconfigure exec sp_configure 'Ad Hoc Distributed Queries',1 RECONFIGURE select * INTO 表名称 FROM openrowset('sqloledb','服务器IP地址';'数据库名称';'数据库密码',数据库.表名称) --使用完成后,关闭Ad Hoc Distributed Queries --EXEC sp_configure 'Ad Hoc Distributed Queries',0 reconfigure exec sp_configure 'show advanced options',0 reconfigure --分离数据库 EXEC sp_detach_db @dbname = 'pubs' --删除日志文件 --再附加 EXEC sp_attach_single_file_db @dbname = 'pubs', @physname = 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf'