SQLserver数据库常用命令


--所有库名
SELECT * FROM sys.databases where name='ipms4s_hrxj_jk'
--表信息
select name,create_date ,modify_date from sys.tables where name='Car_GpsData'
select * from sysobjects where xtype= 'U'


--表字段信息
select column_name,data_type,'-' as column_comment from information_schema.columns
where table_name='RPS_CaseData' and table_schema='dbo' 


--表创建时间、更新时间、行数
select schema_name(t.schema_id) as [Schema], 
t.name as TableName,
t.create_date ,
t.modify_date,
i.rows as [RowCount]
from sys.tables as t, sysindexes as i
where t.name='RPS_CaseData' and  t.object_id = i.id and i.indid <=1

--所有schema信息
select * from sys.schemas s 
--库占用空间
exec sp_spaceused 
--表占用空间
exec sp_spaceused 'dbo.RPS_CaseData'