人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動(dòng)態(tài)

通過系統(tǒng)數(shù)據(jù)庫獲取用戶所有數(shù)據(jù)庫中的視圖、表、存儲過程

發(fā)布日期:2021-12-29 04:10 | 文章來源:腳本之家

復(fù)制代碼 代碼如下:

--設(shè)置sql 可以獲取實(shí)例名稱
sp_configure 'xp_cmdshell' , 1;
go
reconfigure;
go

--獲取實(shí)例名
EXEC sys .xp_cmdshell 'sqlcmd -Lc'

--獲取所有數(shù)據(jù)庫
Select * FROM Master..SysDatabases order by Name

--獲取數(shù)據(jù)庫所有表
use yeekang ---數(shù)據(jù)庫名稱
select * from sysobjects where type = 'U' order by name

--獲取指定表字段
select * from syscolumns where id= OBJECT_ID('Userinfo' )

SELECT
表名 =case when a .colorder= 1 then d.name else '' end ,
表說明 =case when a .colorder= 1 then isnull(f .value, '') else '' end,
字段序號 =a. colorder,
字段名 =a. name,
標(biāo)識 =case when COLUMNPROPERTY ( a .id, a.name ,'IsIdentity')= 1 then '√' else '' end ,
主鍵 =case when exists( SELECT 1 FROM sysobjects where xtype ='PK' and name in (
SELECT name FROM sysindexes WHERE indid in(
SELECT indid FROM sysindexkeys WHERE id = a .id AND colid =a. colid
))) then '√ ' else '' end,
類型 =b. name,
占用字節(jié)數(shù) =a. length,
長度 =COLUMNPROPERTY( a.id ,a. name,'PRECISION' ),
小數(shù)位數(shù) =isnull( COLUMNPROPERTY(a .id, a.name ,'Scale'), 0),
允許空 =case when a .isnullable= 1 then '√' else '' end,
默認(rèn)值 =isnull( e.text ,''),
字段說明 =isnull( g.[value] ,'')

復(fù)制代碼 代碼如下:

FROM syscolumns a
left join systypes b on a. xusertype=b .xusertype
inner join sysobjects d on a. id=d .id and d .xtype= 'U' and d.name <>'dtproperties'
left join syscomments e on a. cdefault=e .id
left join sys. extended_properties g on a.id =g. major_id and a.colid =g. minor_id
left join sys. extended_properties f on d.id =f. major_id and f. minor_id=0
where a .id= OBJECT_ID('Userinfo' )
order by a. id,a .colorder
另一例:

在SQL Server數(shù)據(jù)庫中每一個(gè)數(shù)據(jù)庫都有一個(gè)sysobjects系統(tǒng)表,這個(gè)表里面存儲了當(dāng)前數(shù)據(jù)庫的所有對象,包括對象表,用戶表,視圖,觸發(fā)器,約束,默認(rèn)值,日志,和存儲過程的信。

先列一下這張表的一些字段名:

name 對象名
id 對象標(biāo)識號
xtype 對象類型
uid 所有者對象的用戶ID
parent_obj 父對象的對象標(biāo)識號
crdate 對象的創(chuàng)建日期
ftcatid 為全文索引注冊的所有用戶表的全文目錄標(biāo)識符
schema_ver 版本號,
category 用于發(fā)布,約束和標(biāo)識

看上上面的字段你應(yīng)該已經(jīng)清楚了吧...
xtype這個(gè)字段就是確定對象類型的...

如果你想獲取數(shù)據(jù)庫中所有的表信息,你可以寫如下的查詢語句:

復(fù)制代碼 代碼如下:

select * from sysobjects where xtype='u'

如果你想獲取數(shù)據(jù)庫中所有的存儲過程的信息,你可以寫如下的查詢語句:

復(fù)制代碼 代碼如下:

select * from sysobjects where xtype='p'

如果你想獲取數(shù)據(jù)庫中所有的視圖信息,你可以寫如下的查詢語句:

復(fù)制代碼 代碼如下:

select * from sysobjects where xtype='v'

如果你想獲取數(shù)據(jù)庫中所有的觸發(fā)器信息,你可以寫如下的查詢語句:

復(fù)制代碼 代碼如下:

select * from sysobjects where xtype='tr'
獲取SQL所有數(shù)據(jù)庫名、所有表名、所有字段名

1.獲取所有數(shù)據(jù)庫名:

Select Name FROM Master..SysDatabases orDER BY Name

2.獲取所有表名:

復(fù)制代碼 代碼如下:

Select Name FROM DatabaseName..SysObjects Where XType='U' orDER BY Name

XType='U':表示所有用戶表;

XType='S':表示所有系統(tǒng)表;

3.獲取所有字段名:

復(fù)制代碼 代碼如下:

Select Name FROM SysColumns Where id=Object_Id('TableName')

方法二。

復(fù)制代碼 代碼如下:

select * from sys.databases
select * from information_schema.tables
select * from information_schema.columns where table_name='tablename'

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部