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

首頁 > 開發 > 綜合 > 正文

使用sql的一些tip

2024-07-21 02:05:54
字體:
來源:轉載
供稿:網友
國內最大的酷站演示中心!
哈爾濱工業大學計算機學院數據庫研究中心 [email protected]如何在sql server 2000中顯示查詢計劃。 使用 sql 查詢分析器以文本方式顯示執行計劃showplan_text and showplan_allthe two set options showplan_text and showplan_all let you see the estimated query plan without actually executing the query. both options also automatically enable the set noexec option, so you don't see any results from your query—you see only the way that sql server has determined is the best method for processing the query. turning noexec on can be a good thing while tuning a query. for example, if you have a query that takes 20 minutes to execute, you might try to create an index that will allow it to run faster. however, immediately after creating a new index, you might just want to know whether the query optimizer will even choose to use that index. if you were actually executing the query every time you looked at its plan, it would take you 20 minutes for every tuning attempt. setting noexec on along with the show plan option will allow you to see the plan without actually executing all the statements. warning since turning on showplan_text or showplan_all implies that noexec is also on, you must set the showplan option to off before you do anything else. for example, you must set showplan_text to off before setting showplan_all to on. 使用 sql 查詢分析器以圖形方式顯示執行計劃 如何使用dbcc page命令來查看數據頁格式例子:use testgoselect * from stugo結果: 首先來看sysindexes關系的內容。數據庫中的每個索引和表在表中各占一行。該表存儲在每個數據庫中。列名數據類型描述idint表 id(如果 indid = 0 或 255)。否則為索引所屬表的 id。statusint內部系統狀態信息。firstbinary(6)指向第一頁或根頁的指針。indidsmallint索引 id: 0 = 該表為新表,對應的表是一個堆1 = 聚集索引>1 = 非聚集255 = 具有 text 或 image 數據的表條目rootbinary(6)如果 indid >= 1 和 1 重復。如果 indid = 255,rows 設置為 0。提供該列是為了向后兼容。select id ,first,indid from sysindexes where id =object_id('stu') and indid in (0,1)dbcc的格式為:dbcc page ({dbid | dbname},filenum,pagenum[,printopt])為了獲得filenum,filenum,執行下面的語句: select id ,first,indid from sysindexes where id =object_id('stu') and indid in (0,1)id first indid4535766540x1900000001000然后運行 dbcc dbcc traceon (3604)godbcc page('test',1,25,1)godbcc 執行完畢。如果 dbcc 輸出了錯誤信息,請與系統管理員聯系。page: (1:25)------------buffer:-------buf @0x18ed5a00---------------bpage = 0x19620000 bhash = 0x00000000 bpageno = (1:25)bdbid = 7 breferences = 24 bstat = 0x9bspin = 0 bnext = 0x00000000 page header:------------page @0x19620000----------------m_pageid = (1:25) m_headerversion = 1 m_type = 1m_typeflagbits = 0x0 m_level = 0 m_flagbits = 0x8008m_objid = 453576654 m_indexid = 0 m_prevpage = (0:0)m_nextpage = (0:0) pminlen = 8 m_slotcnt = 8m_freecnt = 7938 m_freedata = 1316 m_reservedcnt = 0m_lsn = (6:166:2) m_xactreserved = 0 m_xdesid = (0:0)m_ghostreccnt = 0 m_tornbits = 2 allocation status-----------------gam (1:2) = allocated sgam (1:3) = not allocatedpfs (1:1) = 0x61 mixed_ext allocated 50_pct_full diff (1:6) = changedml (1:7) = not min_logged data:-----slot 0, offset 0x60-------------------record type = primary_record record attributes = null_bitmap variable_columns 19620060: 00080030 0000000c 01000002 7a001300 0..............z19620070: 6f6168 haoslot 1, offset 0x73-------------------record type = primary_record record attributes = null_bitmap variable_columns 19620073: 00080030 00000002 01000002 6b001200 0..............k19620083: 6961 aislot 2, offset 0x85-------------------record type = primary_record record attributes = null_bitmap variable_columns 19620085: 00080030 0000002d 01000002 77001300 0...-..........w19620095: 676e61 angslot 3, offset 0x98-------------------record type = primary_record record attributes = null_bitmap variable_columns 19620098: 00080030 0000000f 01000002 66001300 0..............f196200a8: 676e65 engslot 4, offset 0xab-------------------record type = primary_record record attributes = null_bitmap variable_columns 196200ab: 00080030 0000004c 01000002 78001100 0...l..........x196200bb: 78 x slot 5, offset 0xbc-------------------record type = primary_record record attributes = null_bitmap variable_columns 196200bc: 00080030 0000005a 01000002 79001100 0...z..........y196200cc: 79 y slot 6, offset 0xcd-------------------record type = primary_record record attributes = null_bitmap 196200cd: 00080010 000000c8 020002 ...........slot 7, offset 0x50e--------------------record type = primary_record record attributes = null_bitmap variable_columns 1962050e: 00080030 000004d2 01000002 7a001600 0..............z1962051e: 6b6f6168 6961 haokaioffset table:-------------row - offset 7 (0x7) - 1294 (0x50e) 6 (0x6) - 205 (0xcd) 5 (0x5) - 188 (0xbc) 4 (0x4) - 171 (0xab) 3 (0x3) - 152 (0x98) 2 (0x2) - 133 (0x85) 1 (0x1) - 115 (0x73) 0 (0x0) - 96 (0x60) dbcc 執行完畢。如果 dbcc 輸出了錯誤信息,請與系統管理員聯系。 分析:數據行的格式19620060: 00080030 0000000c 01000002 7a001300 0..............z19620070: 6f6168 haoid = 12 name = zhao 30 00 0800 0c000000 0200 00 0100 1300 7a68616f300008000c000000020000010013007a68616f狀態位未使用找到第一 列的位置第八個字節開始定長第一列的值為 c=12總列數為2null標志均可以為非空變長列數為1列第一個變長結束的位置在0x13=19結束第一個變長列zhao object_id返回數據庫對象標識號。語法object_id ( 'object' )參數'object'要使用的對象。object 的數據類型為 char 或 nchar。如果 object 的數據類型是 char,那么隱性將其轉換成 nchar。返回類型int dbcc extentinfo利用dbcc extentinfo得到屬于一個對象的所有盤區的列表。其語法為:dbcc extentinfo(dbname,tablename,indexid) sql 會把聚集索引的數據頁用鏈表連接起來,但對于堆不需要。例如有 以及 其數據行如下(選例):19918060: 00080030 0a0a0001 01000004 4e002b00 0............+.n19918070: 48207765 20657269 6f4a202d 6f6e2062 ew hire - job no19918080: 70732074 66696365 646569 t specifiedjob_id = 1 job_desc = new hire - job not specifiedmin_lvl = 10 max_lvl = 10 00080030 0a0a0001 01000004 4e002b00 48207765 20657269 6f4a202d 6f6e2062 70732074 66696365 6465693000080001000a列數開始的位置small int 第一列數據tiny int第三列數據0a04000001002btiny int第四列數據列數為4均可空變長列數為1第一個變長列結束的位置剩下的為字符串 replicate以指定的次數重復字符表達式。語法replicate ( character_expression , integer_expression ) 參數character_expression由字符數據組成的字母數字表達式。character_expression 可以是常量或變量,也可以是字符列或二進制數據列。integer_expression是正整數。如果 integer_expression 為負,則返回空字符串。返回類型varcharcharacter_expression 必須為可隱性轉換為 varchar 的數據類型。否則,使用 cast 函數顯式轉換 character_expression。for example:replicate(cast(1 as varchar(1)),250) or replicate(‘1’,250) and they are the same. 如果是cast(1 as char)則,類型轉化后的1所占的空間為32個字節如果是cast(1 as varchar(1)),則1所占的空間為1個字節。 primary key unique在sql中primary key 和unique的處理是一樣的。系統會自動在primary key 和unique所約束的列上建立聚集索引。查詢優化器基于位于索引的存在而不是基于一個烈被聲明為主碼的事實來作出決策。例如: 在建立it表后,系統自動為it建立聚集索引,同時上圖表明了sysobjects,syscolumns和sysindexes的關系。待插入兩行后,結果如下: 當我們插入insert into it values(3,null)分析文件格式1990408d: 00080010 00000003 020002 ...........id = 3 name = [null] 10 00 0800 03000000 0200 021000080003000000020002第一列數據在第八個字節處一個列數據為3共有兩列null = 10 第二列為空,結束 建立索引是如不指名是clustered或nonclustered,則系統默認為非簇集的,即indid > 1 syslogins中保留了所有登陸用戶的信息 sp_dboption顯示或更改數據庫選項。不能在 master 或 tempdb 數據庫上使用 sp_dboption。向后兼容性支持 sp_dboption。使用 alter database 設置數據庫選項。語法sp_dboption [ [ @dbname = ] 'database' ] [ , [ @optname = ] 'option_name' ] [ , [ @optvalue = ] 'value' ]參數[@dbname =] 'database'在其中設置指定選項的數據庫的名稱。database 的數據類型為 sysname,默認值為 null。[@optname =] 'option_name'要設置的選項的名稱。沒有必要輸入完整的選項名稱。microsoft? sql server? 可識別名稱中任何獨有的部分。如果選項名稱包含空格或者關鍵字,請將選項名稱用引號引起來。如果省略此參數,sp_dboption 將列出處于打開狀態的選項。option_name 的數據類型為 varchar(35),默認值為 null。 [@value =] 'value'option_name 的新設置。如果省略此參數,sp_dboption 將返回當前設置。value 可以是 true、false、on 或 off。value 的數據類型為 varchar(10),默認值為 null。返回代碼值0(成功)或 1(失敗) 可以用sp_dboption 來設置批量insertselect into/bulkcopy當為 true 時,允許使用 select into 語句和快速大容量復制。 累積求和問題-t-sql系列累積求和問題 有一表: col1 value running_tot 1 10 0 (10) 2 15 0 (25) 3 50 0 (75)若要將value列累積求和的結果放到running_tot 列,可以這樣:declare @i intset @i=0update tableset @[email protected]+value或者declare @i intset @i=0update tableset @[email protected]+valuesfrom table
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 红安县| 安岳县| 随州市| 江都市| 云浮市| 资中县| 博湖县| 景德镇市| 宁陵县| 乌鲁木齐县| 龙井市| 鄂尔多斯市| 丹寨县| 鄂尔多斯市| 葫芦岛市| 八宿县| 和林格尔县| 乳山市| 蓬溪县| 西贡区| 安国市| 盱眙县| 苏州市| 阿荣旗| 龙陵县| 定襄县| 大连市| 林口县| 海晏县| 昭觉县| 密山市| 锦屏县| 五指山市| 内乡县| 金沙县| 屏南县| 巴南区| 旺苍县| 鲁山县| 东兴市| 内丘县|