最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2014年04月07日 16:10:37   作者:  
本文主要講了通過系統(tǒng)數(shù)據(jù)庫獲取用戶所有數(shù)據(jù)庫中的視圖、表、存儲過程的方法,大家參考使用吧

復制代碼 代碼如下:

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

--獲取實例名
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,
標識 =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,
默認值 =isnull( e.text ,''),
字段說明 =isnull( g.[value] ,'')

復制代碼 代碼如下:

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ù)庫中每一個數(shù)據(jù)庫都有一個sysobjects系統(tǒng)表,這個表里面存儲了當前數(shù)據(jù)庫的所有對象,包括對象表,用戶表,視圖,觸發(fā)器,約束,默認值,日志,和存儲過程的信。

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

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

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

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

復制代碼 代碼如下:

select * from sysobjects where xtype='u'

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

復制代碼 代碼如下:

select * from sysobjects where xtype='p'

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

復制代碼 代碼如下:

select * from sysobjects where xtype='v'

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

復制代碼 代碼如下:

select * from sysobjects where xtype='tr'


獲取SQL所有數(shù)據(jù)庫名、所有表名、所有字段名

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

Select Name FROM Master..SysDatabases orDER BY Name

2.獲取所有表名:

復制代碼 代碼如下:

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

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

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

3.獲取所有字段名:

復制代碼 代碼如下:

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

方法二。

復制代碼 代碼如下:

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

相關(guān)文章

最新評論

重庆市| 嘉峪关市| 三台县| 渑池县| 资溪县| 巴塘县| 新巴尔虎右旗| 盐山县| 巧家县| 逊克县| 图片| 平昌县| 中西区| 洛扎县| 仪征市| 康保县| 泉州市| 方城县| 武强县| 常熟市| 福鼎市| 濮阳市| 崇仁县| 内丘县| 深泽县| 湘西| 久治县| 双流县| 秭归县| 开江县| 丽江市| 五常市| 玛沁县| 蓬莱市| 沛县| 临湘市| 托克托县| 尚义县| 宁国市| 盐山县| 宝清县|