sql server 查詢表名,儲存過程,列名等

2022-04-14 17:50:43 字數 903 閱讀 9296

--1:獲取當前資料庫中的所有使用者表

select name from sysobjects where xtype='u' and status>=0

--2:獲取某乙個表的所有字段

select name from syscolumns where id=object_id(n'表名')

select a.* from sysobjects a, syscomments b where a.id = b.id and b.text like '%表名%'

--4:檢視當前資料庫中所有儲存過程

select name as 儲存過程名稱 from sysobjects where xtype='p'

--5:查詢使用者建立的所有資料庫

select * from master..sysdatabases d where sid not in(select sid from master..syslogins where name='sa')

或者select dbid, name as db_name from master..sysdatabases where sid <> 0x01

--6:查詢某乙個表的字段和資料型別

select column_name,data_type from information_schema.columns

where table_name = n'表名'

--7:獲取資料庫檔案路徑

select ltrim(rtrim(filename)) from 資料庫名..sysfiles where charindex('mdf',filename)>0

orselect ltrim(rtrim(filename)) from 資料庫名..sysfiles where charindex('ldf',filename)>0

查詢SQL Server中的表名

sqlconnection conn new sqlconnection server uid sa pwd 123 database 08 09cgywdb connection timeout 2 conn.open sqlcommand comm new sqlcommand select o...

Sql Server 查詢表名的備註

查詢表名描述 ms description select tbs.name 表名,ds.value 描述 from sys.extended properties ds left join sysobjects tbs on ds.major id tbs.id where ds.minor id ...

SQL Server 快速換表名

經常在我們的業務系統中,表的增長比較快,表的資料量非常龐大,這時我們需要建立乙個新表來替代它,那怎麼快速的把這新錶方上去呢?如人工操作,有可能是會影響業務系統的,所以我們考慮用命令的方式來處理。主要的方式是就是使用系統自帶的儲存過程 sp rename exec sp rename oldtable...