




免費預(yù)覽已結(jié)束,剩余1頁可下載查看
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
-查詢結(jié)果導(dǎo)出到excelSqlServerexec master.xp_cmdshell bcp select * from mydatabase.dbo.mytable queryout c:temp.xls -c -q -S. -Usa -P1-excel導(dǎo)入到SqlServerBULK INSERT temp1 FROM c:temp1.xls -收縮數(shù)據(jù)庫-首先截斷事務(wù)日志 backup log mydatabase with no_log -收縮數(shù)據(jù)庫 dbcc shrinkdatabase(mydatabase,0)-查SqlServer視圖sqlselect text from syscomments where id=object_id(reportsbaseview)select * from information_schema.views-查SqlServer:表名select * from information_schema.tables where table_name like %MYTABLE%-查Oracle:表名select * from sys.all_tables where table_name = MYTABLE-查Sqlserver列名select * from information_schema.columns where table_name = MYTABLE-查Orable:列名select * from sys.all_tab_cols where table_name = MYTABLE-查Sqlserver列描述SELECT *FROM :fn_listextendedproperty (NULL, user , dbo, table, MYTABLE, column, default)-查Orable:列描述select * from sys.all_col_comments where table_name = MYTABLE-為查詢結(jié)果添加序號(pkId必須是整數(shù)類型)select number1=(select count(userId) from tuserset as t2 where t2.pkId=t1.pkId),userId,setName from tuserset as t1-插入100條測試記錄declare i intset i=500while (i600)begininsert into MYTABLE (invitesetid,invitesetno,invitesetname,managerid,projectid,invitesetstatus,projecttypeid)values(i,i,i,100001,136,0,11)set i=i+1end-查詢每個表有幾條記錄declare colId varchar(50)DECLARE detailCustom_Cursor CURSOR FORselect top 90 table_name as tableName from information_schema.tables order by tableName-select table_name as tableName from information_schema.tables where table_name not in (select top 90 table_name from information_schema.tables order by table_name)OPEN detailCustom_CursorFETCH NEXT FROM detailCustom_Cursorinto colIdbegin tran t1declare sql varchar(8000)set sql = WHILE FETCH_STATUS = 0BEGINif(len(sql)=7800)begin set sql = sql + select +colId+ as tableName,count(*) as data from +colId set sql = sql + union all endFETCH NEXT FROM detailCustom_Cursorinto colIdENDset sql = sql + select -1,-1exec(sql)commit tran t1CLOSE detailCustom_CursorDEALLOCATE detailCustom_CursorC#與sql相關(guān)1,取1條sql語句除了某幾列,其他列的都查出來,在aspx頁面中寫:protected string GetExtraSql(string tableName,string exceptionColumns)string returnString = String.Empty;string sql = select top 1 * from +tableName;DataSet temp = wdxl.Commfile.Dblib.GetDataSet(sql);if(temp!=null)sql = select ;DataTable tableObj = temp.Tables0;for(int i=0;itableObj.Columns.Count;i+)/如果找不到則添加if(!StringInArray(exceptionColumns,tableObj.Columnsi.ToString()sql += tableObj.Columnsi+,;int flag = sql.Length;sql = sql.Substring(0,flag-1);sql += from +tableName;returnString = sql;return returnString;protected bool StringInArray(string arrayObj,string data)bool returnValue = false;for (int i=0;iarrayObj.Length;i+)if(arrayObji.ToUpper()=data.ToUpper()returnValue = true;break;return returnValue;-查詢另外一個數(shù)據(jù)庫服務(wù)器的表數(shù)據(jù):SELECT * FROM OPENDATASOURCE(SQLOLEDB,Data Source=2;database=mydatabase;user id=sa;Password=1).mydatabase.dbo.mytable-在sqlserver2005執(zhí)行上面語句可能報權(quán)限錯誤,需要開啟一下相關(guān)參數(shù):exec sp_configure show advanced options,1RECONFIGURE WITH OVERRIDEexec sp_configure Ad Hoc Distributed Queries,1RECONFIGURE WITH OVERRIDE-另一種方式:用鏈接服務(wù)器查詢另外一個數(shù)據(jù)庫服務(wù)器的表數(shù)據(jù)-建立鏈接服務(wù)器EXEC sp_addlinkedserver mycomputer, , MSDASQL, NULL, NULL, DRIVER=SQL Server;SERVER=03;UID=sa;PWD=1;GO-建立鏈接服務(wù)器登錄映射exec sp_addlinkedsrvloginrmtsrvname=mycomputer,useself=false,locallogin=Administrators,rmtuser=sa,rmtpassword=1select * from mycomputer.mydatabase.dbo.users-SqlServer批量改某一列的類型,temp1為零時表declare col1 varchar(50)declare col2 varchar(50)DECLARE detailCustom_Cursor CURSOR FORselect column_name col1,table_name col2 from information_schema.columns where data_type = decimal OPEN detailCustom_CursorFETCH NEXT FROM detailCustom_Cursorinto col1,col2begin tran t1WHILE FETCH_STATUS = 0BEGINbegin declare sql varchar(255) set sql = alter table +col2+ alter column +col1+ int null insert into temp1 values (sql)endFETCH NEXT FROM detailCustom_Cursorinto col1,col2ENDcommit tran t1CLOSE detailCustom_CursorDEALLOCATE detailCustom_Cursor-為查詢結(jié)果添加一列序號Select (select Count(*) from FIELDDICTIONARY T where T.FIELDDICTIONARYid=FIELDDICTIONARY.FIELDDICTIONARYid) as Nbr ,* From FIELDDICTIONARY order by nbr asc-Oracle中的newid()SELECT SYS_GUID() FROM DUAL-監(jiān)控oracle中占用磁盤I/O較高的sql語句select a.username,b.block_gets,b.consistent_gets,b.physical_reads,b.block_changes,b.consistent_changes,c.sql_textfrom v$session a,v$sess_io b,v$sqltext cwhere a.sid=b.sid AND a.sql_address=c.addressAND a.username IS NOT NULLorder by a.username,c.sql_id,c.piece-Oracle創(chuàng)建及獲取表的描述,及字段描述信息-創(chuàng)建表描述COMMENT ON TABLE myTable is 表的描述信息-創(chuàng)建字段描述COMMENT ON COLUMN myTable.ID is 字段的描述信息-取得表描述select * from user_tab_comments where comments is not null-取得字段描述select * from user_col_comments where comments is not null-SqlServer創(chuàng)建及獲取表的描述,及字段描述信息-創(chuàng)建表描述EXEC sp_addextendedproperty 描述類別(可自定義), 表的描述信息, user, dbo, table, myTableName, null, null-創(chuàng)建字段描述EXEC sp_addextendedproperty 描述類別(可自定義), 字段的描述信息,
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2026學(xué)年安徽省淮南市大通區(qū)數(shù)學(xué)三上期末試題含解析
- 2024年西藏林芝地區(qū)米林縣數(shù)學(xué)三年級第一學(xué)期期末質(zhì)量跟蹤監(jiān)視模擬試題含解析
- 2024年柳州市三江侗族自治縣三上數(shù)學(xué)期末學(xué)業(yè)質(zhì)量監(jiān)測模擬試題含解析
- 2024年淮安市楚州區(qū)三年級數(shù)學(xué)第一學(xué)期期末質(zhì)量跟蹤監(jiān)視模擬試題含解析
- 分析化學(xué)第1章 分析化學(xué)概論課件
- 行政法學(xué)全球視野試題及答案
- 執(zhí)業(yè)護士考試患者關(guān)懷與心理疏導(dǎo)能力的提升與溝通技巧試題及答案
- 自考行政管理的考試技巧分享試題及答案
- 疾病預(yù)防控制的護理試題與答案
- 2025年執(zhí)業(yè)藥師考試常見誤區(qū)大全試題及答案
- 大數(shù)據(jù)導(dǎo)論(計科2103-4)學(xué)習(xí)通超星期末考試答案章節(jié)答案2024年
- 《地方導(dǎo)游基礎(chǔ)知識》7.3 青海 地方導(dǎo)游基礎(chǔ)知識-題庫及答案
- 小學(xué)美術(shù)人教版六年級上冊 教案-點的集合
- 浙江省金華市義烏市東陽市2024年小升初英語試卷( 含筆試解析無聽力原文無音頻)
- 感覺統(tǒng)合教育指導(dǎo)師理論考試復(fù)習(xí)題庫(含答案)
- SQL語句創(chuàng)建學(xué)生信息數(shù)據(jù)庫表的示例學(xué)生信息數(shù)據(jù)庫表
- 輿情風(fēng)險應(yīng)對處置
- 2024河南中考數(shù)學(xué)備考 二次函數(shù)圖象與性質(zhì)綜合題、交點問題 (課件)
- 快速入門穿越機-讓你迅速懂穿越機
- 數(shù)字電子技術(shù)(廣東工業(yè)大學(xué))智慧樹知到期末考試答案章節(jié)答案2024年廣東工業(yè)大學(xué)
- 人工智能對書法技法的革新
評論
0/150
提交評論