您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > Sybase IQ SQL开发指南_v1.1
SybaseIQSQLwangb@global-tec.net1590118532913671101290BeijingGlobalTechnologyCo.Ltd.200961¾¾¾T-SQLW-SQL¾¾¾9¾¾T-SQLW-SQL¾¾¾¾bulkinserts¾“”¾IQIQ’’IQ¾IQ¾IQ¾ABISABISCMSCMSOthersOthersETL/stagingdatabaseOLAPReportAdhocqueries(1)ABISABISCMSCMSOthersOthersBCP(ASE)stagingdatabase(ASE)OLAPReportAdhocqueries••ASEETL•bcp(2)ABISABISCMSCMSOthersOthersBCP(IQ)stagingdatabase(ASE)OLAPReportAdhocqueriesLoadTableInsertLocation•IQ!!!¾9¾T-SQLW-SQL¾¾¾¾“”I/O3NF¾()“”99“”9“”3NF¾9999–HG–999“”–“”“”“”DATEDATETIMESMALLDATETIMETIMESTAMP–TINYINT(1byte)SMALLINT(2)INTEGER(4)BIGINT(8)–NUMERICDECIMAL(:126:38;ASE180)–CHAR(n)VARCHAR(n)19“”9NULLNOTNULL99¾¾Column-WiseDataStructures¾¾Bit-WiseIndexing¾¾Continued…Bit-WiseIndexingIQ¾¾B-Tree¾¾¾FastProjection(FP)Index¾Alsoknownasthe“DefaultIndex”ServercreatestheindexnameintheformASIQ_IDX_…_FPAlterTableDropcolumn_name¾ProjectingdataintheSELECTlistWildcardsearch-LIKE'%sys%'ExpressionCalculation-SUM(A+B)JoinOperations–matchesupcolumnvalues¾FPIndexStorage¾Storagemethoddependsonthecardinalityofthecolumn¾“”()9––¾12DBAIQUniqueConstraintsyntaxFlatFP’¾–Continued…1ByteFP¾Continued…2ByteFP¾LookuptablecreatedwithalldistinctvaluesContinued…IQUnique()Constraint¾CreateTablecustomer(idchar(10)NOTNULLIQUnique(3000),…)¾256values-Single-byte(1-byteFPindex)255and65537-Two-byte(2-byteFPindex)Defaultvalueis65,537(FlatFP)¾Minimize_StorageDatabaseOption¾EliminatesneedtoaddIQUnique()forallcolumnsinscripts¾Thedatabaseoptioncouldbe‘turnedoff'foratableFPIndexStorage¾SybaseIQQueryoptimizerexploitstheseindexesI/O¾¾¾¾LowFast(LF)Continued…87654321RowIDLFIndex¾…Equality(=),Inequality(!=),INandNOTINsearchargumentsMIN(),MAX(),COUNT(),COUNTDISTINCTargumentGroupByJoins(inplaceofanHGindex)¾RangeSearches(,,=,Between,etc)¾HighGroup(HG)HGIndex¾Allkey/joincolumns(regardlessofcardinality)SearchargumentsinWHEREclauseGROUPBYSELECTDISTINCT,COUNTDISTINCTclauses¾¾HighNonGroup(HNG)¾SELECTSUM(sales)FROMcustomer(2*64)+(3*32)+(2*16)+(1*8)+(3*4)+(2*2)+(3*1)=283HNGIndex¾Exception:Date/DatetimeandoptimizedFPindexcolumnsCannotbedeclaredUniqueCannotbeacompositeindex¾RangesBETWEENMIN(),MAX(),SUM()andAVG()functions¾¾Compare(CMP)CMPIndex¾¾,=,,=,=¾PurchasePrice,ListCostEmployeeID,ManagerIDDate/DatetimeDate(DATE),Time(TIME),andDatetime(DTTM)Indexes¾ADATEindexisonlyforcolumnsofdatatypeDATEusedtoprocessqueriesinvolvingdatequantitiesATIMEindexisonlyforcolumnsofdatatypeTIMEusedtoprocessqueriesinvolvingtimequantitiesADTTMindexisonlyforcolumnsofdatatypeDATETIMEorTIMESTAMPusedtoprocessqueriesinvolvingdatetimequantitiesContinued…IQ¾9999IQ9–Ad-HocjoinFP“”FPIQ¾IQ9–SELECT–SUMA+B–WHERELIKESUBSTRcolumnlike“%x”9––GROUPBYORDERBY–MINMAXSUMAVGCOUNT–COUNTDISTINCTSELECTDISTINCT–WHERE==BETWEENINIQ¾IQ9––SELECTDISTINCTCOUNTDISTINCT–COUNTMINMAX–GROUPBYORDERBY–IN–9–AVGSUM–BETWEEN–RootStringWHEREcust_namelike“Stan%”likeFP¾¾9T-SQLW-SQL¾¾¾IQ¾IQASASQL999T-SQL999W-SQL99IQ¾IQT-SQLW-SQLIQIQDML9T-SQLT-SQL9999999IQ¾T-SQLbegindeclare@jinteger,@kintegerselect@k=30set@j=10declare@iintegerselect100into@iendIQ¾T-SQLW-SQL999999IQ¾W-SQLbegindeclarejinteger;declareiinteger;declarekinteger;setk=30;setj=10;select100intoi;//endIQSQL¾DDLDMLDMLPPTDCL¾IQSQL¾LocalvariablesConnectioin-levelvariables(staticvariables)Globalvariables¾999999999IQSQL¾,ASE99Localvariables¾IQASEIQ9IQ3SQLLanguageElements¾T-SQLW-SQL¾IFexpression...statement...[ELSE[IFexpression]statement]...……if@i10print'@i=%1!',@ielseprint'@i=%1!',@i-10……¾……ifi10thenprint'i=%1!',ielseprint'i=%1!',i-10endif……CASE¾T-SQLDMLCASEselectkhh,jgh,bz,casewhenleft(cpbm,3)='101'thenzbyeelse0endashqckpjyefromcrmo_gg_ckyepjwheretjrq=@datadateCASE¾¾…………¾WHILE(SELECTAVG(unit_price)FROMproduct)$30BEGINDELETEFROMproductWHEREunit_price=MAX(unit_price)IF(SELECTMAX(unit_price)FROMproduct)$50BREAKENDDCL¾SETi=1;WHILEi=10LOOPINSERTINTOCounters(number)VALUES(i);SETi=i+1;ENDLOOP;¾¾SQLEXECUTE¾SQLEXECUTEIMMEDIATE99¾¾SQLbegindeclare@iinteger,@jinteger;set@i=101select@j=100if@i100thenprint'@i=%1!',@i;elseprint'@i=%1!',@j-@i;endifendbegindeclare@iinteger,@jintegerset@i=101select@j=100if@i100print'@i=%1!',@ielseprint'@i=%1!',@j-@iendIQSQL¾3TypesofTemporaryTables9“”–createtable#temptable(col1int)–selectinto#tablename9–declarelocaltemporarytabletemp(col1int)–Behavejustlike“#”tables9–createglobaltemporarytabletemp(col1int)–Tablesstructureisstaticacrossconnectionsandreboots–IQSQL¾99–13T-SQLW-SQL–2W-SQL9–1committruncateable–23commit“OnCommitPreserveRows”¾¾¾T-SQLW-SQL9¾¾IQSQL¾9999“”commitwithholdCurosorIQSQL¾T-SQLbegindeclare@fnamechar(15)declare@lnamechar(20)declarecust_cursorcursorforselectfname,lnamefromcustomerwhereid110opencust_cursorfetchcust_cursorinto@fname,@lnamewhile(@@sqlstatus=0)beginfetchcust_cursorinto@fname,@lnameprint'@fname=%1!,@lname=%2!',@fname,@lnameendclosecust_cursordeallocatecursorcust_cursorend;IQSQL¾W-SQL(1)BEGINdeclarecust_cursorcursorforselectfnamefromcustomerwhereid110;DECLAREnameCHAR(40);OPENcust_cursor;curL
本文标题:Sybase IQ SQL开发指南_v1.1
链接地址:https://www.777doc.com/doc-5036340 .html