国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

Sqlserver中的一些技巧

2024-07-21 02:07:56
字體:
來源:轉載
供稿:網友

獲取一個sqlserver上的所有數據庫信息 用存儲過程 sp_databases

在查詢分析其中執行命令exec sp_databases

結果:master 14464 null
model 1280 null
msdb 14336 null
northwind 4352 null
pubs 2560 null
store 1912 null
tempdb 8704 null
test 1272 null

獲取一個數據庫的所有表用存儲過程 sp_tables

執行命令: use northwind exec sp_tables 結果:

northwind dbo sysusers system table null
northwind dbo categories table null
northwind dbo customercustomerdemo table null
northwind dbo customerdemographics table null
northwind dbo customers table null
northwind dbo dtproperties table null
northwind dbo employees table null
northwind dbo employeeterritories table null
(.......)


獲取一個表的列信息用存儲過程sp_columns

運行exec sp_columns 'orders' (orders為表名) 結果

northwind dbo orders orderid 4 int identity 10 4 0 10 0 null null 4 null null 1 no  56
northwind dbo orders customerid -8 nchar 5 10 null null 1 null null -8 null 10 2 yes 39
northwind dbo orders employeeid 4 int 10 4 0 10 1 null null 4 null null 3 yes 38
northwind dbo orders orderdate 11 datetime 23 16 3 null 1 null null 9 3 null 4 yes 111
northwind dbo orders requireddate 11 datetime 23 16 3 null 1 null null 9 3 null 5 yes 111
northwind dbo orders shippeddate 11 datetime 23 16 3 null 1 null null 9 3 null 6 yes 111
northwind dbo orders shipvia 4 int 10 4 0 10 1 null null 4 null null 7 yes 38
northwind dbo orders freight 3 money 19 21 4 10 1 null (0) 3 null null 8 yes 110
northwind dbo orders shipname -9 nvarchar 40 80 null null 1 null null -9 null 80 9 yes 39
(......)

獲取一個數據庫的所有存儲過程,可以用

select * from sysobjects where type='p'

執行所得結果:

custordersdetail 789577851 p  1 0 1610612736 0 0 0 2000-08-06 01:34:52.513
custordersorders 805577908 p  1 0 1610612736 0 0 0 2000-08-06 01:34:52.733
custorderhist 821577965 p  1 0 1610612736 0 0 0 2000-08-06 01:34:52.967
salesbycategory 837578022 p  1 0 1610612736 0 0 0 2000-08-06 01:34:53.200
(......)

sysobjects這個東西還有其他一些用法,具體可參照sqlserver連機幫助

在ado.net里面獲取一個存儲過程的參數信息:
    sqlconnection connect = new sqlconnection(connectionstring);
    connect.open();
    sqlcommand sc = new sqlcommand("salesbycategory", connect); // salesbycategory 為northwind數據庫中的一個存儲過程.
    sc.commandtype = commandtype.storedprocedure;
    sqlcommandbuilder.deriveparameters(sc);
    foreach(sqlparameter param in sc.parameters)
    {
    console.writeline("name:{0}, size:{1}, type:{2}, value:{3},direction:{4}, isnull:{5}", param.parametername, param.size, param.dbtype, param.value, param.direction, param.isnullable);
    }

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平遥县| 包头市| 中牟县| 固安县| 通海县| 克山县| 临猗县| 南丰县| 德昌县| 社旗县| 东乌珠穆沁旗| 乐安县| 当雄县| 泊头市| 获嘉县| 云龙县| 泸州市| 万安县| 双辽市| 内黄县| 通化市| 康乐县| 钟祥市| 稷山县| 鄯善县| 米林县| 德庆县| 茶陵县| 辛集市| 陆河县| 莱州市| 保靖县| 莫力| 宁武县| 建宁县| 洪泽县| 伊宁市| 苏尼特左旗| 雅江县| 雅安市| 山阳县|