DB2 SQLÐÔÄÜÓÅ»¯Ïà¹ØµÄ10´óÒªËØ
ÏÂÃæÌá³öÁË10ÌõºÍDB2 SQLÐÔÄÜÏà¹ØµÄ10ÌõÒòËØ£º
1¡¢ÌṩÊʵ±µÄͳ¼ÆÐÅÏ¢
¶ÔDB2ÓÅ»¯¹ÜÀíÆ÷£¨otimizer£©¶øÑÔ£¬ÈçºÎ¸ü¼ÓÓÐЧµÄÖ´ÐÐSQLÓï¾äÊÇÓÉ´æÔÚÓÚDB2 catalogÖеÄͳ¼ÆÐÅÏ¢¾ö¶¨µÄ£¬ÓÅ»¯Æ÷ÀûÓÃÕâЩÐÅÏ¢¾ö¶¨×îÓÅ»¯µÄ·¾¶¡£
Òò´Ë£¬ÎªÁ˱£³ÖϵͳÄܹ»×ö³ö×î¼ÑÑ¡Ôñ£¬ÐèÒª¾³£µÄÔËÐÐRunstatsÃüÁÀ´±£³Öϵͳͳ¼ÆÐÅÏ¢µÄ¼°Ê±ÓÐЧ¡£ÔÚ¹¤×÷¸ººÉºÜ´óµÄÉú²ú»·¾³ÖУ¬¾³£ÔËÐÐRunstatsÊǺܱØÒªµÄ£¬ÎªÁ˼õÉÙ½øÐÐͳ¼Æ¶Ôϵͳ´øÀ´µÄÓ°Ï죬¿ÉÒÔʹÓÃSampling¼¼Êõ¡£
2¡¢ÔÚSQLÓï¾äÖо¡Á¿Ê¹ÓÃStage 1µÄν´Ê
ÊôÓÚStage 1µÄSQLν´ÊÓÉData Manager´¦Àí£¬¶øÊôÓÚStage 2µÄSQLÓÉRelational Data ServerÖ´ÐС£ÔÚ´¦ÀíЧÂÊÉÏ£¬Data Manager¸üÓÐÓÅÊÆ£¬Òò´Ë£¬Èç¹û¿ÉÄܵĻ°¾¡Á¿°ÑSQLÓï¾äд³ÉÄܹ»ÔÚStage 1Ö´Ðеġ£Èç¹ûÄܹ»½áºÏIndexÀ´È·¶¨SQLÓï¾äÖеÄν´Ê£¬ÄÇô½«»á¸ü¼ÓÌá¸ßSQLÖ´ÐеÄЧÂÊ¡£Òò´Ë£¬ÔÚдSQL²éѯÓï¾äµÄʱºò£¬Òª½áºÏIndexµÄ¶¨ÒåÒÔ¼°Î½´ÊÃèдµÄÑ¡Ôñ£¬¾¡¿ÉÄܵÄÈÃSQLÔÚStage 1ÔËÐС£
3¡¢ÔÚSQLÖнöÑ¡ÔñÐèÒªµÄÁÐ
ÔÚSQLÓï¾äÖУ¬½öÖ¸¶¨³ÌÐòÐèÒªµÄÁлáÓÐÀûÓÚÌá¸ßSQLÔËÐеÄÐÔÄÜ¡£Èç¹û²ÉÓÃSelect *ÕâÖÖģʽ£¬½«»á¸ø¿Í»§¶ËµÄÓ¦ÓóÌÐò´øÀ´¶îÍâµÄ´¦Àí¹¤×÷£¬²¢ÐèÒª¸ü¶àµÄÄÚ´æµÈ×ÊÔ´¡£¶Ô·þÎñÆ÷¶Ë¶øÑÔ£¬¶àÓàµÄÁÐÔÚÅÅÐò¹ý³ÌÖлáÔö´óSort¹¤×÷Îļþ£¬²¢Òò´Ëµ¼ÖÂÅÅÐòËٶȵÄϽµ£¬²¢ÐèÒª¸ü¶àµÄ´æ´¢×ÊÔ´¡£ÔÚÍøÂç´«Êä¹ý³ÌÖУ¬Ò²½«´«ÊäһЩ²»±ØÒªµÄÊý¾Ý£¬½µµÍÍøÂçЧÂÊ¡£
4¡¢½öÑ¡ÔñÐèÒªµÄÐÐ
²éѯµÄÐÐÔ½ÉÙ£¬²éѯµÄËٶȺÍÏìÓ¦ËٶȾÍÔ½¿ì¡£²éѯ»ñµÃµÄÿһÐÐÊý¾Ý£¬¶¼¾ÀúÁË´Ó´æ´¢É豸-¡µ»º³å³Ø-¡µÅÅÐòºÍת»»-¡µÍøÂç´«Êä-¡µÓ¦ÓóÌÐòµÈһϵÁйý³Ì¡£ÔÚÊý¾ÝµÄ²éѯ¹ý³ÌÖУ¬Êý¾Ý¿â¹ÜÀíÆ÷½«»á×÷ºÜ¶àÊý¾ÝµÄ¹ýÂ˹¤×÷£¬Èç¹ûÓÐÐí¶à²¢²»ÐèÒªµÄÐдÓÊý¾Ý¿âÖмìË÷³öÀ´£¬½«»áÀ˷Ѻܶ಻±ØÒªµÄ´¦Àíʱ¼ä£¬Òò´Ë£¬ÔÚSQLÓï¾äµÄ׫д¹ý³ÌÖÐÓ¦¸ÃÏêϸµÄÖ¸¶¨²éѯÌõ¼þ£¬½ö²éѯÐèÒªµÄÐС£
5¡¢Èç¹ûÊý¾Ý¿âÖеÄÊý¾ÝºÜ³¤Ê±¼ä²»±ä£¬ÔÚSQL¾¡Á¿Ê¹Óó£Á¿»òÕß×Ö·û¡£
ÔÚSQLÖÐʹÓÃÖ÷»ú±äÁ¿£¬ÊÇΪÁËʹϵͳÊÊÓ¦²»¶Ï±ä»¯µÄÍⲿ»·¾³¡£ÔÚSQL³ÌÐòÖÐʹÓÃÖ÷»ú±äÁ¿Äܹ»Ê¹Ó¦ÓóÌÐò²»ÐèÒªÖØа󶨾ͿÉÒÔÖ±½ÓÖ´ÐÐеÄSQL¶¨Òå¡£µ«ÊÇÕâÖÖÁé»îÐÔÊÇÒÔ½µµÍDB2ÓÅ»¯¹ÜÀíÆ÷µÄÐÔÄÜΪ´ú¼ÛµÄ¡£ÔÚ°üº¬Ö÷»ú±äÁ¿µÄSQLÓï¾äÖУ¬DB2ÓÅ»¯¹ÜÀíÆ÷ÒÔĬÈϵĹÀ¼ÆÖµÀ´½øÐÐSQL·¾¶µÄÑ¡Ôñ£¬¶ø²»ÊǸù¾ÝCatalogÖеÄͳ¼ÆÐÅÏ¢£¬ÕâÖÖÑ¡ÔñºÜ¶àʱºò¶¼²»ÊÇ×îÓÅ»¯µÄ¡£Òò´Ë£¬Ê¹Óó£Á¿»òÕß×Ö·û´úÌæÖ÷»ú±äÁ¿ÔÚ³¤Ê±¼ä¹Ì¶¨²»±äµÄ»·¾³Öн«»á±ÈʹÓÃÖ÷»ú±äÁ¿¸üÓÐÓÅÊÆ¡£
6¡¢Ê¹Êý×Ö¡¢ÈÕÆÚµÈÊý¾ÝÀàÐÍÏàÆ
Ïà¹ØÎĵµ£º
Ò»¡¢»ù´¡
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý¿â
drop database dbname
3¡¢ËµÃ÷£º±¸·Ýsql server
--- ´´½¨ ±¸·ÝÊý¾ÝµÄ device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'
--- ¿ªÊ¼ ±¸·Ý
BACKUP DATABASE pubs TO testBack
......
ÔÚTypes of data compression in SQL Server 2008Õâƪ²©¿ÍÖУ¬ Sunil AgarwalÌáµ½ÁËÔÚSQL Server 2008ÖвÉÓõÄÁ½ÖÖѹËõ²ßÂÔ£º
£¨1£©ÒԱ䳤¸ñʽ´æ´¢ËùÓеĶ¨³¤Êý¾ÝÀàÐÍ¡£ÔÚ±¾ÏµÁеÄÉÏһƪÎÄÕÂÖУ¬ÎÒÌáµ½¹ýÔÚSQL Server 2005 SP2ÖÐÌṩµÄʹÓÃvardecimalÀàÐÍÀ´´æ´¢decimal/numericÊý¾ÝÀàÐÍÒÔ½ÚÊ¡´æ´¢¿Õ¼äµ ......
1, ʲôÊÇͳ¼ÆÐÅÏ¢
ÒÔÏÂÊǹٷ½µÄ¶Ôͳ¼ÆÐÅÏ¢µÄÃèÊö£º
°´ÕÕĬÈÏÉèÖã¬Èç¹û±íÖеÄijÁÐûÓÐË÷Òý£¬ÔòSQL Server»á×Ô¶¯Îª¸ÃÁд´½¨Í³¼Æ¡£È»ºó£¬²éѯÓÅ»¯Æ÷ÆÀ¹À¸ÃÁÐÖÐÊý¾Ý·Ö²¼·¶Î§µÄͳ¼ÆÐÅÏ¢£¬ÒÔÑ¡ÔñÒ»¸ö¸üΪÓÐЧµÄ²éѯ´¦Àí·½°¸¡£·Ö±æ×Ô¶¯´´½¨µÄͳ¼ÆºÜ¼òµ¥£¬ÔÚSQL Serve ......
SQLÖÐWHERE×Ó¾äÖпÉÒÔÀûÓÃLIKEÀ´Æ¥ÅäÏàËƵÄÊý¾ÝÏµ±Ê±Îҵõ½µÄ½áÂÛÊÇ¿ÉÒÔʹÓÃ"%"À´Æ¥Åä×Ö·û´®£¬ÔÚSPUFIÖÐʹÓ㬵ÄÈ·¿ÉÒԵõ½×Ö·û´®Æ¥ÅäµÄЧ¹û¡£È磺
SELECT * from TEST
WHERE TESTID LIKE "CZX%";
ÉÏÃæÕâ¾äÔÚSPUFIÖÐÌ ......
½«ÁÐת»»ÎªÐУ¬Ï൱ÓÚ½«±í½á¹¹Ðýת90¶È
T_Student ±í
Stud_ID
Sex
Name
1
ÄÐ
Tom
2
Å®
Anne
3
ÄÐ
Jack
Ö´ÐÐ: Exec proColumnToRow ’T_Student’,’Name’,’ New_ID’
ת»»ºóµÄ±í
New_ID
Tom
Anne
Jack
Stud_ID
1
2
3
Sex
ÄÐ
Å®
ÄÐ
& ......