CK REFERENCE SOFTWARE GUIDE • DATABASES SQL (Structured Query Language): A standard language for accessing data stored in databases While it is '"standardizcd," there are many variations, each with its own proprietary extensions and features The latest standard is ANSI SQL 99 (which was preccded by SQL-92) This guidc will discuss the ANSI SQL-99 standard and variations implemented in Microsoft SQL Datatypcs: The various data formats that can he stored; summari7ed in labk, to make it easy to sec the types supportcd and their namcs :x ~=- Server'" 2000 (other versions of Microsoft SQL Serve and other database vendors are similar as the content discussed in this guide is introductory; refer to the product's documentation for any differences) BIT TINYINT SMALLINT • • • • • • • • •IINT COVERED IN THIS GUIDE BIGINT This guide assumes understanding of bas ic database concepts IBM started out SQL as a SEQUEL (Structured English QUEry Language ) in the 1970s - It was a standard language to query databases - This has changed very little in its scope and purpose over the years The American National Standards Institute (ANSI) designed a standard that allowed database vendors better interoperability between versions and made it easier to learn and migrate between database vendors - Their first standard was released in 1986, and was updated in 1989, 1992, and 1999 One of SQL-92's big changes was the introduction of conformance levels - They were, from simplest to the most complete, implementations of the standard: Entry, Intermediate, and Full - Each level encompasscd all of the preceding levels and added new capabilities - To claim ANS I compliance, the product had to at least support the Entry level SQL-99 added, among other things, object-oriented datatypcs - It also changed Entry Icvel conformance to Co re SQL: 1999 - Also changcd the other levels to sets of additional features - Any database that meets the core spec and at least I additional feature set is Enhanced SQL 1999 complim;t •••••••• Notation SELECT A SQL keyword: type thi s text exactly as shown BOLD ALL CAPS SELECT Statements and options that are part of the ANSI standard I"ilic Text Dall/hose_nome F LOAT [(II)] SMALLMONEY MONEY CHAR[(nl] NCHAR[(n)j Replace the italic text with the text desc ribed in italics; ex Da/{tba.lc_"i1I11 C with MyDB VARCHAR[(n)] ORDER BY Field_NOllie Optional syntax; the command will work without specifing this parameter; not type [] NVARCHAR[(II)j ORDER BY Fie/d_Nolllel , Fieil'-NlIllle2 Multiple parameters may be specified separated by commas; in some cases multiple optional parameters may be specified as noted in the usc of square brackets: not type NOT NULL CHECK (Sa lary < 100) Multiple parameters may be specified, separated by spaces; in some cases multiple optional parameters may be specified, as noted in the usc of square brackets; not type lJ; in this example, the field must not be blank and the value < 100 FROM Jobs Parameters (or I of them if multiple options arc givcn) must be specified; in this example, thc FROM clause must be specified in a SELECT statement NUL L I NOT NULL Only I of the options li sted may be chosen; in this case NULL or NOT NULL III) ( 15) Entered the des ired number in parenthesis BINARY[(n)] Expressioll Field_Nallle or A field, vari able, or combinat ion of fields and/or variables separated by operators or a lilllction involving fields and/or variables VARBINARY[illl] Definition of parameter referenced elsewhere IMAGE [] [Option [, n]] [Optioll "n]] 1: SUM 1-1 C nee *Note th at not all statements or all possible options for every statement will be covered in this guide II ° _ Stores or I only Stores integers Irom through 255 in I byte Stores integers from -J27/lH through 32 767 in :2 b~tes Stores integers from -2,147,4 83 (,-1 through 2,147,483,647 in4 bytes Store, integers Irom -l),22J ,372,0.J6,g~,775,XOR through 9,2 2J ,372,036,854,775 ,H07 in X byte, Stores numbers with lip to 38 di gits nf pn.: ~is iLlIl (p, total including s); a specified numl,,'r 1'1' those digits (s) may be ri ght of the ck cimal Takcs to 17 bytes to store, depending on the precision desired: ° decimal and nUllleri c are synony mous REAL To make syntax simpler to write, the following notations are used in syntax descriptions: ALL CAPS DECIMAL[(P[ ,s]) or NUMERIC[(p[,s]) +~_~:-=-~_":""" TEXT NTEXT Stores approximate numerics " ith a range Ilf 3.40E + 3li through - LI RE - 3X, and LI XI' - JX through 3.40E t 3X in -I b~tes with digits ofpreci sion in scientific notation; Same as f1oat(24) Stores approximate numerics with a range of - 1.79F 308 through -2.23 E - 308, and 2.23 1: -3 (J~ through 1.79E + 308 in either or bytes \I itl! (if II ] Thc critcria uscd with any DML stal ement is specified using WHER E ; without it , all row s arc ret urned (or c hanged or del eted, depending on the s tat emelll): most DML sta te mcnts will use WH E RE DML continued: Clause: From Join [FROM { } • 'C t; WITH CUBE: Similar to WITH ROLLUP, but a summa ry row is added for every possible combination of va lues, thus returning the same number of rows, regardless of the order specified in the GROUP BY clause; the g reater the number of field s specified in the GROUP BY clause, the greater the number of summary rows (exponentia lly) Note that distinct aggregates (ex SUM(DISTINCT ON 100 will return the total sales of each book that starts with F-M and has sold at least 100 copies), but can be used without GROUP BY, in which case it acts just like WHERE WHERE can't be used to filter grouped data (as it applies before the data is grouped) but HAVI NG can , and may also refe rence agg regate data HAVING overrides GROU P BY ALL, so the records that don't meet the HAVING condition(s) specified not appear in the output It is generally more efficient to filter with WHERE whenever possible and use HAVING only when necessary; less data to be grouped and then late r discarded by the HAVING condition(s) Unlike most of the other clauses listed here, HAVING can only be used with SELECT Statement: Overview UPDATE {tab1e_ name view_ name} SET {co1umn_ name = { expression DEFAULT I NULL} I @variab1e = expression} [, n) «[FROM {< tabl e _ sou rce> } [ , n]] [WHERE