SQL Reference Guide. For use with c-treesql Server. This manual describes syntax and semantics of SQL language statements and elements for c-treesql.

Size: px
Start display at page:

Download "SQL Reference Guide. For use with c-treesql Server. This manual describes syntax and semantics of SQL language statements and elements for c-treesql."

Transcription

1 SQL Reference Guide For use with c-treesql Server This manual describes syntax and semantics of SQL language statements and elements for c-treesql.

2 Copyright FairCom Corporation All rights reserved. Portions Dharma Systems, Inc. All rights reserved. Information in this document is subject to change without notice. FairCom Corporation shall not be liable for any incidental, direct, special or consequential damages whatsoever arising out of or relating to this material, even if FairCom Corporation has been advised, knew or should have known of the possibility of such damages. The software described in this manual is furnished under a license agreement or nondisclosure agreement. The software may be used or copied only in accordance with the terms of this agreement. It is against the law to copy this software on magnetic tape, disk or any other medium for any purpose other than for backup or archival purposes. This manual contains information protected by copyright. No part of this manual may be photocopied or reproduced in any form without prior written consent from FairCom Corporation Use, duplication, or disclosure whatsoever by the Government shall be expressly subject to restrictions as set forth in subdivision (b)(3)(ii) for restricted rights in computer software and subdivision (b)(2) for limited rights in technical data, both as set in FairCom welcomes your comments on this document and the software it describes. Send comments to: Documentation Comments FairCom Corporation 2100 Forum Blvd., Suite C Columbia, MO Phone: Fax: Electronic Mail: support@faircom.com Web Page: c-treesql, c-treesql ODBC, c-treesql ODBC SDK, and c-treesql Integrator are trademarks of FairCom Corporation. The following are third-party trademarks: DBstore is a trademark of Dharma Systems, Inc. Microsoft and MS-DOS are registered trademarks, and ODBC, Windows, Windows 95 and Windows NT are trademarks of Microsoft Corporation. Java, Java Development Kit, Solaris, SPARC, SunOS, and SunSoft are trademarks of Sun Microsystems, Inc. All other trademarks and registered trademarks are the property of their respective holders

3 Contents Introduction Purpose of This Manual ii-vii Audience ii-vii Structure of This Document ii-vii Conventions ii-viii Related Documentation ii-ix 1 SQL Language Elements 1.1 SQL Identifiers Conventional Identifiers Delimited Identifiers Data Types Character Data Types Exact Numeric Data Types Approximate Numeric Data Types Date-Time Data Types Bit String Data Types Query Expressions Inner Joins Outer Joins Search Conditions Logical Operators: OR, AND, NOT Relational Operators Basic Predicate Quantified Predicate BETWEEN Predicate NULL Predicate LIKE Predicate EXISTS Predicate IN Predicate Outer Join Predicate Expressions Concatenated Character Expressions Numeric Arithmetic Expressions Date Arithmetic Expressions Conditional Expressions Literals Numeric Literals Character String Literals i

4 ii Date-Time Literals Date Literals Time Literals Timestamp Literals Date-Time Format Strings Date Format Strings Time Format Strings Functions Aggregate Functions AVG COUNT MAX MIN SUM Scalar Functions ABS function (ODBC compatible) ACOS function (ODBC compatible) ADD_MONTHS function (extension) ASCII function (ODBC compatible) ASIN function (ODBC compatible) ATAN2 function (ODBC compatible) CASE (SQL-92 Compatible) CAST function (SQL-92 compatible) CEILING function (ODBC compatible) CHAR function (ODBC compatible) CHARTOROWID (extension) CHR function (extension) COALESCE (SQL-92 compatible) CONCAT function (ODBC compatible) CONVERT function (extension) CONVERT function (ODBC compatible) COS function (ODBC compatible) CURDATE function (ODBC compatible) CURTIME function (ODBC compatible) DATABASE (ODBC compatible) DAYNAME function (ODBC compatible) DAYOFMONTH function (ODBC compatible) DAYOFWEEK function (ODBC compatible) DAYOFYEAR function (ODBC compatible) DB_NAME (extension) DECODE function (extension)

5 DEGREES function (ODBC compatible) DIFFERENCE function (ODBC compatible) EXP function (ODBC compatible) FLOOR function (ODBC compatible) GREATEST function (extension) HOUR function (ODBC compatible) IFNULL function (ODBC compatible) INITCAP function (extension) INSERT function (ODBC compatible) INSTR function (extension) LAST_DAY function (extension) LCASE function (ODBC compatible) LEAST function (extension) LEFT function (ODBC compatible) LENGTH function (ODBC compatible) LOCATE function (ODBC compatible) LOG10 function (ODBC compatible) LOWER function (SQL-92 compatible) LPAD function (extension) LTRIM function (ODBC compatible) MINUTE function (ODBC compatible) MOD function (ODBC compatible) MONTHNAME function (ODBC compatible) MONTH function (ODBC compatible) MONTHS_BETWEEN function (extension) NEXT_DAY function (extension) NOW function (ODBC compatible) NULLIF (SQL-92 compatible) NVL function (extension) OBJECT_ID function (extension) PI function (ODBC compatible) POWER function (ODBC compatible) PREFIX function (extension) QUARTER function (ODBC compatible) RADIANS function (ODBC compatible) RAND function (ODBC compatible) REPLACE function (ODBC compatible) RIGHT function (ODBC compatible) REPEAT function (ODBC compatible) ROWID (extension) ROWIDTOCHAR (extension) iii

6 RPAD function (extension) RTRIM function (ODBC compatible) SECOND function (ODBC compatible) SIGN function (ODBC compatible) SIN function (ODBC compatible) SOUNDEX function (ODBC compatible) SPACE function (ODBC compatible) SQRT function (ODBC compatible) SUBSTR function (extension) SUBSTRING function (ODBC compatible) SUFFIX function (extension) SUSER_NAME function (extension) SYSDATE function (extension) SYSTIME function (extension) SYSTIMESTAMP function (extension) TAN function (ODBC compatible) TIMESTAMPADD function (ODBC compatible) TIMESTAMPDIFF function (ODBC compatible) TO_CHAR function (extension) TO_DATE function (extension) TO_NUMBER function (extension) TO_TIME function (extension) TO_TIMESTAMP function (extension) TRANSLATE function (extension) UCASE function (ODBC compatible) UID function (extension) UPPER function (SQL-92 compatible) USER function (ODBC compatible) USER_NAME function (extension) WEEK function (ODBC compatible) YEAR function (ODBC compatible) SQL Statements 2.1 Conventions Alter Table CALL COMMIT WORK Connect Create Index CREATE PROCEDURE CREATE SYNONYM Create Table iv

7 2.9.1 Column Constraints Table Constraints Create Trigger CREATE VIEW DELETE Disconnect Drop Index DROP PROCEDURE DROP SYNONYM Drop Table DROP TRIGGER DROP VIEW Get Diagnostics GRANT INSERT Lock Table RENAME REVOKE ROLLBACK WORK SELECT ORDER BY Clause Set Connection Set Transaction Isolation SET SCHEMA UPDATE Update Statistics A SQL Reserved Words A.1 SQL Reserved Words A-1 B Error Messages B.1 Overview B-1 B.2 c-treesql Error Codes, SQLSTATE Values, Messages B-2 C System Catalog Tables C.1 Overview C-1 C.2 System Catalog Tables Definitions C-2 D System Limits D.1 Maximum Values for c-treesql Attributes D-1 E Glossary E.1 Terms Index-1 Tables Table 2-1: Permitted Inconsistencies in Transactions Table A-1: Reserved Words A-1 v

8 vi Table B-1: Error Codes Used by c-treesql Components B-1 Table B-2: Error Codes and Messages B-2 Table C-1: System Catalog Table Definitions C-2 Table D-1: System Limits D-1

9 Introduction PURPOSE OF THIS MANUAL This manual describes the syntax and semantics of c-treesql language statements and elements. AUDIENCE This manual is intended for application programmers writing database applications using the c-treesql environment. To get the most out of this manual, you should be familiar with the concepts of the c-treesql environment. If you are new to c-treesql, see the Quick Start and c-treesql Embedded SQL User s Guide for supplementary information. Unless otherwise noted, you can use the SQL syntax described in this manual in the c-treesql interactive SQL environment. For more information on interactive SQL, see the c-treesql ISQL and Tools Reference Guide. STRUCTURE OF THIS DOCUMENT The manual contains the following chapters and appendixes: Chapter 1 Chapter 2 Appendix A Appendix B Appendix C Describes language elements common to many SQL statements. Provides detailed reference material on each SQL statement, in alphabetic order. Lists the c-treesql reserved words. Lists the c-treesql error messages. Summarizes the tables in the c-treesql system catalog. Appendix D Lists the maximum sizes for various attributes of a c- treesql environment and queries. FairCom Corporation vii

10 SQL Reference Appendix E Contains a glossary of terms you should know. SYNTAX CONVENTIONS diagrams appear in Courier type and use the following conventions: UPPERCASE lowercase Uppercase type denotes reserved words. You must include reserved words in statements, but they can be upper or lower case. Lowercase type denotes either user-supplied elements or names of other syntax diagrams. User-supplied elements include names of tables, host-language variables, expressions, and literals. diagrams can refer to each other by name. If a diagram is named, the name appears in lowercase type above and to the left of the diagram, followed by a double-colon (for example, privilege ::). The name of that diagram appears in lowercase in diagrams that refer to it. { } Braces denote a choice among mandatory elements. They enclose a set of options, separated by vertical bars ( ). You must choose at least one of the options. [ ] Brackets denote an optional element or a choice among optional elements. Vertical bars separate a set of options.... A horizontal ellipsis denotes that the preceding element can optionally be repeated any number of times. ( ), ; Parentheses and other punctuation marks are required elements. Enter them as shown in syntax diagrams. viii FairCom Corporation

11 Introduction RELATED DOCUMENTATION c-treesql ISQL and Tools Reference Guide c-treesql Embedded SQL User s Guide c-treesql ODBC Driver Guide c-treesql JDBC Driver Guide c-treesql Guide to Java Stored Procedures and Triggers Describes the c-treesql interactive SQL utility, ISQL, and other database administration utilities. Describes how to develop host language programs containing embedded SQL statements that access c-treesql environments. Describes c-treesql support for the ODBC interface and how to configure the c-treesql ODBC Driver. Describes c-treesql support for the JDBC interface, configuring the c-treesql JDBC Driver, and how applications connect to databases through the driver. Describes how to write and use Java stored procedures and triggers Java routines which contain SQL statements and are stored in a database. ODBC, JDBC, and SQL applications call stored procedures, while triggers are invoked automatically by database updates. FairCom Corporation ix

12 SQL Reference x FairCom Corporation

13 Chapter 1 SQL Language Elements This chapter describes language elements that are common to many SQL statements. diagrams in other chapters often refer to these language elements without detailed explanation. The major syntax elements described in the following sections are: Identifiers User-supplied names for elements such as tables, views, cursors, and columns. SQL statements use those names to refer to the elements. Data types Control how SQL stores column values. Query expressions Retrieve values from tables. Query expressions form the basis of other SQL statements and syntax elements. Search conditions Specify a condition that is true or false about a given row or group of rows. Query expressions and UPDATE statements specify search conditions to restrict the number of rows in the result table. Expressions A symbol or string of symbols used to represent or calculate a single value in an SQL statement. When SQL encounters an expression, it retrieves or calculates the value represented by the expression and uses that value when it executes the statement. Literals A type of SQL expression that specify a constant value. Some SQL constructs allow literals but prohibit other forms of expressions. Date-time format strings Control the output of date and time values. c-treesql interprets format strings and replaces them with formatted values. Functions A type of SQL expression that returns a value based on the argument supplied. Aggregate functions calculate a single value for a collection of rows in a result table. Scalar functions calculate a value based on another single value. FairCom Corporation 1-1

14 c-treesql 1.1 SQL IDENTIFIERS SQL syntax requires users to supply names for elements such as tables, views, cursors, and columns when they define them. SQL statements must use those names to refer to the table, view, or other element. In syntax diagrams, SQL identifiers are shown in lowercase type. The maximum length for SQL identifiers is 32 characters. There are two types of SQL identifiers: Conventional identifiers Conventional Identifiers Delimited identifiers enclosed in double quotation marks Unless they are delimited identifiers (Refer to Delimited Identifiers on page 1-3), SQL identifiers must: Begin with an uppercase or lowercase letter Contain only letters, digits, or the underscore character ( _ ) Not be reserved words Except for delimited identifiers, SQL does not distinguish between uppercase and lowercase letters in SQL identifiers. It converts all names to lowercase, but statements can refer to the names in mixed case. The following examples show some of the characteristics of conventional identifiers: -- Names are case-insensitive: CREATE TABLE TeSt (CoLuMn1 CHAR); INSERT INTO TEST (COLUMN1) VALUES('1'); 1 record inserted. SELECT * FROM TEST; COL record selected TABLE TEST; COLNAME NULL? TYPE LENGTH 1-2 FairCom Corporation

15 SQL Language Elements Delimited Identifiers column1 -- Cannot use reserved words: CREATE TABLE TABLE (COL1 CHAR); CREATE TABLE TABLE (COL1 CHAR); * error(-20003): error Delimited identifiers are SQL identifiers enclosed in double quotation marks ("). Enclosing a name in double quotation marks preserves the case of the name and allows it to be a reserved word and special characters. (Special characters are any characters other than letters, digits, or the underscore character.) Subsequent references to a delimited identifier must also use enclosing double quotation marks. To include a double-quotation-mark character in a delimited identifier, precede it with another double-quotation mark. The following SQL example shows some ways to create and refer to delimited identifiers: CREATE TABLE "delimited ids" ( """" CHAR(10), "_uscore" CHAR(10), """quote" CHAR(10), " space" CHAR(10) ); INSERT INTO "delimited ids" ("""") VALUES('text string'); 1 record inserted. SELECT * FROM "delimited ids"; " _USCORE "QUOTE SPACE text strin 1 record selected CREATE TABLE "TABLE" ("CHAR" CHAR); FairCom Corporation 1-3

16 c-treesql 1.2 DATA TYPES The SQL statements CREATE TABLE and ALTER TABLE specify data types for each column in the tables they define. This section describes the data types SQL supports for table columns. There are several categories of SQL data types: Character Exact numeric Approximate numeric Date-time Bit String All the data types can store null values. A null value indicates that the value is not known and is distinct from all non-null values. data_type :: char_data_type exact_numeric_data_type approx_numeric_data_type date_time_data_type bit_string_data_type Character Data Types Refer to Character String Literals on page 1-38 for details on specifying values to be stored in character columns. char_data_type :: { CHARACTER CHAR } [(length)] { CHARACTER VARYING CHAR VARYING VARCHAR } [(length)] LVARCHAR LONG VARCHAR 1-4 FairCom Corporation

17 SQL Language Elements Arguments { CHARACTER CHAR } [(length)] Type CHARACTER (abbreviated as CHAR) corresponds to a null terminated character string with the maximum length specified. The default length is 1. The maximum length is LVARCHAR LONG VARCHAR Type LONG VARCHAR corresponds to an arbitrarily long character string with a maximum length limited by the specific storage system. The arbitrary size and unstructured nature of LONG data types restrict where they can be used. LONG columns are allowed in select lists of query expressions and in INSERT statements. INSERT statements can store data from columns of any type except LONG VARBINARY into a LONG VARCHAR column, but LONG VARCHAR data cannot be stored in any other type. Conditional expressions, arithmetic expressions, and functions cannot specify LONG columns. UPDATE statements cannot specify LONG columns. { CHARACTER VARYING CHAR VARYING VARCHAR } [(length)] Type CHARACTER VARYING corresponds to a variable-length character string with the maximum length specified. The default length for columns defined as CHARACTER VARYING is 1. The maximum length is Exact Numeric Data Types Refer to Numeric Literals on page 1-38 for details on specifying values to be stored in numeric columns. exact_numeric_data_type :: TINYINT SMALLINT INTEGER BIGINT FairCom Corporation 1-5

18 c-treesql NUMERIC NUMBER [ ( precision [, scale ] ) ] DECIMAL [(precision, scale)] MONEY [(precision)] Arguments TINYINT Type TINYINT corresponds to an integer value stored in one byte. The range of TINYINT is -128 to 127. SMALLINT Type SMALLINT corresponds to an integer value of length 2 bytes. The range of SMALLINT is to INTEGER Type INTEGER corresponds to an integer of length 4 bytes. The range of values for INTEGER columns is -2 ** 31 to 2 ** BIGINT Type BIGINT corresponds to an integer of length 8 bytes. The range of values for BIGINT columns is -2 ** 63 to 2 ** NUMERIC NUMBER [ ( precision [, scale ] ) ] Type NUMERIC corresponds to a number with the given precision (maximum number of digits) and scale (the number of digits to the right of the decimal point). By default, NUMERIC columns have a precision of 32 and scale of 0. If NUMERIC columns omit the scale, the default scale is 0. The range of values for a NUMERIC type column is -n to +n where n is the largest number that can be represented with the specified precision and scale. If a value exceeds the precision of a NUMERIC column, SQL generates an overflow error. If a value exceeds the scale of a NUMERIC column, SQL rounds the value. NUMERIC type columns cannot specify a negative scale or specify a scale larger than the precision. The following example shows what values will fit in a column created with a precision of 3 and scale of 2: insert into t4 values(33.33); error(-20052): Overflow error 1-6 FairCom Corporation

19 SQL Language Elements insert into t4 values(33.9); error(-20052): Overflow error insert into t4 values(3.3); 1 record inserted. insert into t4 values(33); error(-20052): Overflow error insert into t4 values(3.33); 1 record inserted. insert into t4 values( ); 1 record inserted. insert into t4 values(3.3555); 1 record inserted. select * from t4; C records selected DECIMAL [(precision, scale)] Type DECIMAL is comparable to type NUMERIC. MONEY [(precision)] Type MONEY is equivalent to type NUMERIC with a fixed scale of Approximate Numeric Data Types Refer to Numeric Literals on page 1-38 for details on specifying values to be stored in numeric columns. approx_numeric_data_type :: REAL DOUBLE PRECISION FairCom Corporation 1-7

20 c-treesql FLOAT [ (precision) ] Arguments REAL Type REAL corresponds to a single precision floating point number equivalent to the C language float type. DOUBLE PRECISION Type DOUBLE PRECISION corresponds to a double precision floating point number equivalent to the C language double type. FLOAT [ (precision) ] Type FLOAT corresponds to a double precision floating point number of the given precision. By default, FLOAT columns have a precision of Date-Time Data Types Refer to Date-Time Literals on page 1-39 for details on specifying values to be stored in date-time columns. See page 1-44 for details on date strings and page 1-45 for details on using format strings to specify the output format of date-time columns. date_time_data_type :: DATE TIME TIMESTAMP Arguments DATE Type DATE stores a date value as three parts: year, month, and day. The range for the parts is: Year: 1 to 9999 Month: 1 to 12 Day: Lower limit is 1; the upper limit depends on the month and the year 1-8 FairCom Corporation

21 SQL Language Elements TIME Type TIME stores a time value as four parts: hours, minutes, seconds, and milliseconds. The range for the parts is: Hours: 0 to 23 Minutes: 0 to 59 Seconds: 0 to 59 Milliseconds: 0 to 999 TIMESTAMP Type TIMESTAMP combines the parts of DATE and TIME Bit String Data Types Arguments bit_string_data_type :: BIT BINARY [(length)] VARBINARY [(length)] LVARBINARY LONG VARBINARY BIT Type BIT corresponds to a single bit value of 0 or 1. SQL statements can assign and compare values in BIT columns to and from columns of types CHAR, VARCHAR, BINARY, VARBINARY, TINYINT, SMALLINT, and INTEGER. However, in assignments from BINARY, VARBINARY, and LONG VARBINARY, the value of the first four bits must be 0001 or No arithmetic operations are allowed on BIT columns. BINARY [(length)] Type BINARY corresponds to a bit field of the specified length of bytes. The default length is 1 byte. The maximum length is 2000 bytes. In interactive SQL, INSERT statements must use a special format to store values in BINARY columns. They can specify the binary values as a bit FairCom Corporation 1-9

22 c-treesql string, hexadecimal string, or character string. INSERT statements must enclose binary values in single-quote marks, preceded by b for a bit string and x for a hexadecimal string: Prefix Suffix Example (for same 2 byte data) bit string b' ' b' ' hex string x' ' x'ad10' char string ' ' 'ad10' SQL interprets a character string as the character representation of a hexadecimal string. If the data inserted into a BINARY column is less than the length specified, SQL pads it with zeroes. BINARY data can be assigned and compared to and from columns of type BIT, CHAR, and VARBINARY types. No arithmetic operations are allowed. VARBINARY [(length)] Type VARBINARY corresponds to a variable-length bit field with the maximum length specified. The default length is 1 and the maximum length is Otherwise, VARBINARY columns have the same characteristics as BINARY. LVARBINARY LONG VARBINARY Type LONG VARBINARY corresponds to an arbitrarily long bit field with the maximum length of less than 2 gigabytes. The arbitrary size and unstructured nature of LONG data types restrict where they can be used. LONG columns are allowed in select lists of query expressions and in INSERT statements. INSERT statements can store data from columns of any type except LONG VARCHAR into a LONG VARBINARY column, but LONG VARBINARY data cannot be stored in any other type. Conditional expressions, arithmetic expressions, and functions cannot specify LONG columns. UPDATE statements cannot specify LONG columns FairCom Corporation

23 SQL Language Elements Query Expressions Description A query expression selects the specified column values from one or more rows contained in one or more tables specified in the FROM clause. The selection of rows is restricted by a search condition in the WHERE clause. The temporary table derived through the clauses of a SELECT statement is called a result table. Query expressions form the basis of other SQL statements and syntax elements: SELECT statements are query expressions with optional ORDER BY and FOR UPDATE clauses. CREATE VIEW statements specify their result table as a query expression. INSERT statements can specify a query expression to add the rows of the result table to a table. UPDATE statements can specify a query expression that returns a single row to modify columns of a row. Some search conditions can specify query expressions. Basic predicates can specify query expressions, but the result table can contain only a single value. Quantified and IN predicates can specify query expressions, but the result table can contain only a single column. The FROM clause of a query expression can itself specify a query expression, called a derived table. query_expression :: query_specification query_expression set_operator query_expression ( query_expression ) set_operator :: { UNION [ ALL ] INTERSECT MINUS } query_specification :: FairCom Corporation 1-11

24 c-treesql SELECT [ALL DISTINCT] { * { table_name alias }. * [, { table_name alias }. * ] expr [ [ AS ] [ ' ] column_title [ ' ] ] [, expr [ [ AS ] [ ' ] column_title [ ' ] ] ]... } FROM table_ref [ { ctree ORDERED } ] [, table_ref [ { ctree ORDERED } ] [ WHERE search_condition ] [ GROUP BY [table.]column_name [ COLLATE collationname ] [, [table.]column_name [ COLLATE collation-name ] ]... [ HAVING search_condition ] table_ref :: table_name [ AS ] [ alias [ ( column_alias [, ] ) ] ] ( query_expression ) [ AS ] alias [ ( column_alias [, ] ) ] [ ( ] joined_table [ ) ] joined_table :: table_ref CROSS JOIN table_ref table_ref [ INNER LEFT [ OUTER ] ] JOIN table_ref ON search_condition Arguments SELECT [ ALL DISTINCT ] DISTINCT specifies that the result table omits duplicate rows. ALL is the default, and specifies that the result table includes all rows. SELECT * { table_name alias }. * Specifies that the result table includes all columns from all tables named in the FROM clause. For instance, the following examples both specify all the columns in the customers table: 1-12 FairCom Corporation

25 SQL Language Elements SELECT * FROM customers; SELECT customers.* FROM customers; The tablename.* syntax is useful when the select list refers to columns in multiple tables, and you want to specify all the columns in one of those tables: SELECT CUSTOMERS.CUSTOMER_ID, CUSTOMERS.CUSTOMER_NAME, ORDERS.* FROM CUSTOMERS, ORDERS SELECT expr [ [ AS ] [ ' ] column_title [ ' ] ] Specifies a list of expressions, called a select list, whose results will form columns of the result table. Typically, the expression is a column name from a table named in the FROM clause. The expression can also be any supported mathematical expression, scalar function, or aggregate function that returns a value. The optional ' column_title ' argument specifies a new heading for the associated column in the result table. Enclose the new title in single or double quotation marks if it contains spaces or other special characters: SELECT order_value, order_value *.2 AS 'order "markup"' FROM orders; ORDER_VALUE ORDER "MARKUP" You can qualify column names with the name of the table they belong to: SELECT CUSTOMER.CUSTOMER_ID FROM CUSTOMERS You must qualify a column name if it occurs in more than one table specified in the FROM clause: SELECT CUSTOMERS.CUSTOMER_ID FROM CUSTOMERS, ORDERS Qualified column names are always allowed even when they are not required. FROM table_ref FairCom Corporation 1-13

26 c-treesql The FROM clause specifies one or more table references. Each table reference resolves to one table (either a table stored in the database or a virtual table resulting from processing the table reference) whose rows the query expression uses to create the result table. There are three forms of table references: A direct reference to a table, view or synonym A derived table specified by a query expression in the FROM clause A joined table that combines rows and columns from multiple tables The usage notes specific to each form of table reference follow. If there are multiple table references, SQL joins the tables to form an intermediate result table that is used as the basis for evaluating all other clauses in the query expression. That intermediate result table is the Cartesian product of rows in the tables in the FROM clause, formed by concatenating every row of every table with all other rows in all tables. FROM table_name [ AS ] [ alias [ ( column_alias [, ] ) ] ] Explicitly names a table. The name listed in the FROM clause can be a table name, a view name, or a synonym. The alias is a name you use to qualify column names in other parts of the query expression. Aliases are also called correlation names. If you specify an alias, you must use it, and not the table name, to qualify column names that refer to the table. Query expressions that join a table with itself must use aliases to distinguish between references to column names. For example, the following query expression joins the table customer with itself. It uses the aliases x and y and returns information on customers in the same city as customer SMITH: SELECT y.cust_no, y.name FROM customer x, customer y WHERE x.name = 'SMITH' AND y.city = x.city ; Similar to table aliases, the column_alias provides an alternative name to use in column references elsewhere in the query expression. If you specify column aliases, you must specify them for all the columns in table_name. Also, if you specify column aliases in the FROM clause, you must use them not the column names in references to the columns FairCom Corporation

27 SQL Language Elements FROM ( query_expression ) [ AS ] alias [ ( column_alias [, ] ) ] Specifies a derived table through a query expression. With derived tables, you must specify an alias to identify the derived table. Derived tables can also specify column aliases. Column aliases provides an alternative name to use in column references elsewhere in the query expression. If you specify column aliases, you must specify them for all the columns in the result table of the query expression. Also, if you specify column aliases in the FROM clause, you must use them, and not the column names, in references to the columns. FROM [ ( ] joined_table [ ) ] Combines data from two table references by specifying a join condition. The syntax currently allowed in the FROM clause supports only a subset of possible join conditions: CROSS JOIN specifies a Cartesian product of rows in the two tables INNER JOIN specifies an inner join using the supplied search condition LEFT OUTER JOIN specifies a left outer join using the supplied search condition You can also specify these and other join conditions in the WHERE clause of a query expression. See page 1-19 for information on "Inner Joins" and page 1-22 for information on "Outer Joins" for more detail on both ways of specifying joins. { ctree ORDERED } Directs the SQL engine optimizer to join the tables in the order specified. Use this clause when you want to override the SQL engine's join-order optimization. This is useful for special cases when you know that a particular join order will result in the best performance from the underlying storage system. Since this clause bypasses join-order optimization, carefully test queries that use it to make sure the specified join order is faster than relying on the optimizer. Note that the braces ( { and } ) are part of the required syntax and not syntax conventions. SELECT sc.tbl 'Table', sc.col 'Column', sc.coltype 'Data Type', sc.width 'Size' FROM systpe.syscolumns sc, systpe.systables st FairCom Corporation 1-15

28 c-treesql { ctree ORDERED } WHERE sc.tbl = st.tbl AND st.tbltype = 'S' ORDER BY sc.tbl, sc.col; WHERE search_condition The WHERE clause specifies a search_condition that applies conditions to restrict the number of rows in the result table. If the query expression does not specify a WHERE clause, the result table includes all the rows of the specified table reference in the FROM clause. The search_condition is applied to each row of the result table set of the FROM clause. Only rows that satisfy the conditions become part of the result table. If the result of the search_condition is NULL for a row, the row is not selected. Search conditions can specify different conditions for joining two or more tables. See page 1-19 for information on "Inner Joins" and page 1-22 for information on "Outer Joins" for more detail. Refer to 1.3 Search Conditions on page 1-24 for details on the different kinds of search conditions. SELECT * FROM customer WHERE city = 'COLUMBIA' AND state = 'MO' ; SELECT * FROM customer WHERE city IN ( SELECT city FROM customer WHERE name = 'SMITH') ; GROUP BY column_name... Specifies grouping of rows in the result table: For the first column specified in the GROUP BY clause, SQL arranges rows of the result table into groups whose rows all have the same values for the specified column. If a second GROUP BY column is specified, SQL then groups rows in each main group by values of the second column FairCom Corporation

29 SQL Language Elements SQL groups rows for values in additional GROUP BY columns in a similar fashion. All columns named in the GROUP BY clause must also be in the select list of the query expression. Conversely, columns in the select list must also be in the GROUP BY clause or be part of an aggregate function. HAVING search_condition The HAVING clause allows conditions to be set on the groups returned by the GROUP BY clause. If the HAVING clause is used without the GROUP BY clause, the implicit group against which the search condition is evaluated is all the rows returned by the WHERE clause. A condition of the HAVING clause can compare one aggregate function value with another aggregate function value or a constant. -- select customer number and number of orders for all -- customers who had more than 10 orders prior to -- March 31st, SELECT cust_no, count(*) FROM orders WHERE order_date < to_date ('3/31/1991') GROUP BY cust_no HAVING count (*) > 10 ; UNION [ALL] Appends the result table from one query expression to the result table from another. The two query expressions must have the same number of columns in their result table, and those columns must have the same or compatible data types. The final result table contains the rows from the second query expression appended to the rows from the first. By default, the result table does not contain any duplicate rows from the second query expression. Specify UNION ALL to include duplicate rows in the result table. -- Get a merged list of customers and suppliers. SELECT name, street, state, zip FROM customer UNION SELECT name, street, state, zip FairCom Corporation 1-17

30 c-treesql FROM supplier ; -- Get a list of customers and suppliers -- with duplicate entries for those customers who are -- also suppliers. SELECT name, street, state, zip FROM customer UNION ALL SELECT name, street, state, zip FROM supplier ; INTERSECT Limits rows in the final result table to those that exist in the result tables from both query expressions. The two query expressions must have the same number of columns in their result table, and those columns must have the same or compatible data types. -- Get a list of customers who are also suppliers. SELECT name, street, state, zip FROM customer INTERSECT SELECT name, street, state, zip FROM supplier ; MINUS Limits rows in the final result table to those that exist in the result table from the first query expression minus those that exist in the second. In other words, the MINUS operator returns rows that exist in the result table from the first query expression but that do not exist in the second. The two query expressions must have the same number of columns in their result table, and those columns must have the same or compatible data types. -- Get a list of suppliers who are not customers. SELECT name, street, state, zip FROM supplier ; MINUS SELECT name, street, state, zip 1-18 FairCom Corporation

31 SQL Language Elements FROM customer; Authorization The user executing a query expression must have any of the following privileges: DBA privilege SELECT permission on all the tables/views referred to in the query_expression. SQL Compliance Environment Related Statements SQL-92. Extensions: { ctree ORDERED } clause, MINUS set operator Embedded SQL, interactive SQL, ODBC applications CREATE TABLE, CREATE VIEW, INSERT, Search Conditions, SELECT, UPDATE Inner Joins Description Inner joins specify how the rows from one table reference are to be joined with the rows of another table reference. Inner joins usually specify a search condition that limits the number of rows from each table reference that become part of the result table generated by the inner join operation. If an inner join does not specify a search condition, the result table from the join operation is the Cartesian product of rows in the tables, formed by concatenating every row of one table with every row of the other table. Cartesian products (also called cross products or cross joins) are not practically useful, but SQL logically processes all join operations by first forming the Cartesian products of rows from tables participating in the join. If specified, the search condition is applied to the Cartesian product of rows from the two tables. Only rows that satisfy the search condition become part of the result table generated by the join. A query expression can specify inner joins in either its FROM clause or in its WHERE clause. For each formulation in the FROM clause, there is an FairCom Corporation 1-19

32 c-treesql equivalent syntax formulation in the WHERE clause. Currently, not all syntax specified by the SQL-92 standard is allowed in the FROM clause. Arguments from_clause_inner_join :: FROM table_ref CROSS JOIN table_ref FROM table_ref [ INNER ] JOIN table_ref ON search_condition where_clause_inner_join :: FROM table_ref, table_ref WHERE search_condition FROM table_ref CROSS JOIN table_ref Explicitly specifies that the join generates the Cartesian product of rows in the two table references. This syntax is equivalent to omitting the WHERE clause and a search condition. The following queries illustrate the results of a simple CROSS JOIN operation and an equivalent formulation that does not use the CROSS JOIN syntax: SELECT * FROM T1; -- Contents of T1 C1 C records selected SELECT * FROM T2; -- Contents of T2 C3 C BB 15 DD 2 records selected SELECT * FROM T1 CROSS JOIN T2; -- Cartesian product C1 C2 C3 C BB DD 1-20 FairCom Corporation

33 SQL Language Elements BB DD 4 records selected SELECT * FROM T1, T2; -- Different formulation, same results C1 C2 C3 C BB DD BB DD 4 records selected FROM table_ref [ INNER ] JOIN table_ref ON search_condition FROM table_ref, table_ref WHERE search_condition These two equivalent syntax constructions both specify search_condition for restricting rows that will be in the result table generated by the join. In the first format, INNER is optional and has no effect. There is no difference between the WHERE form of inner joins and the JOIN ON form. Equi-joins An equi-join specifies that values in one table equal some corresponding column's values in the other: -- For customers with orders, get their name and order info, : SELECT customer.cust_no, customer.name, orders.order_no, orders.order_date FROM customers INNER JOIN orders ON customer.cust_no = orders.cust_no ; -- Different formulation, same results: SELECT customer.cust_no, customer.name, orders.order_no, orders.order_date FROM customers, orders WHERE customer.cust_no = orders.cust_no ; FairCom Corporation 1-21

34 c-treesql Self joins A self join, or auto join, joins a table with itself. If a WHERE clause specifies a self join, the FROM clause must use aliases to have two different references to the same table: -- Get all the customers who are from the same city as customer SMITH: SELECT y.cust_no, y.name FROM customer AS x INNER JOIN customer AS y ON x.name = 'SMITH' AND y.city = x.city ; -- Different formulation, same results: SELECT y.cust_no, y.name FROM customer x, customer y WHERE x.name = 'SMITH' AND y.city = x.city ; Outer Joins Description An outer join between two tables returns more information than a corresponding inner join. An outer join returns a result table that contains all the rows from one of the tables even if there is no row in the other table that satisfies the join condition. In a left outer join, the information from the table on the left is preserved: the result table contains all rows from the left table even if some rows do not have matching rows in the right table. Where there are no matching rows in the left table, SQL generates null values. In a right outer join, the information from the table on the right is preserved: the result table contains all rows from the right table even if some rows do not have matching rows in the left table. Where there are no matching rows in the right table, SQL generates null values. SQL supports two forms of syntax to support outer joins: In the WHERE clause of a query expression, specify the outer join operator (+) after the column name of the table for which rows will not be preserved in the result table. Both sides of an outer-join search condition in a WHERE clause must be simple column references. This syntax allows both left and right outer joins FairCom Corporation

35 SQL Language Elements For left outer joins only, in the FROM clause, specify the LEFT OUTER JOIN clause between two table names, followed by a search condition. The search condition can contain only the join condition between the specified tables. FairCom's SQL implementation does not support full (two-sided) outer joins. from_clause_inner_join :: FROM table_ref LEFT OUTER JOIN table_ref ON search_condition where_clause_inner_join :: WHERE [table_name.]column (+) = [table_name.]column WHERE [table_name.]column = [table_name.]column (+) Examples The following example shows a left outer join. It displays all the customers with their orders. Even if there is not a corresponding row in the orders table for each row in the customer table, NULL values are displayed for the orders.order_no and orders.order_date columns. SELECT customer.cust_no, customer.name, orders.order_no, orders.order_date FROM customers, orders WHERE customer.cust_no = orders.cust_no (+) ; The following series of examples illustrates the outer join syntax: SELECT * FROM T1; -- Contents of T1 C1 C records selected SELECT * FROM T2; -- Contents of T2 C3 C4 FairCom Corporation 1-23

Reference Guide c-treeace SQL Reference

Reference Guide c-treeace SQL Reference Reference Guide c-treeace SQL Reference Reference Guide c-treeace SQL Reference Copyright Notice Copyright 1992-2017 FairCom Corporation. All rights reserved. No part of this publication may be stored

More information

Introduction to Computer Science and Business

Introduction to Computer Science and Business Introduction to Computer Science and Business This is the second portion of the Database Design and Programming with SQL course. In this portion, students implement their database design by creating a

More information

Course Outline and Objectives: Database Programming with SQL

Course Outline and Objectives: Database Programming with SQL Introduction to Computer Science and Business Course Outline and Objectives: Database Programming with SQL This is the second portion of the Database Design and Programming with SQL course. In this portion,

More information

Senturus Analytics Connector. User Guide Cognos to Tableau Senturus, Inc. Page 1

Senturus Analytics Connector. User Guide Cognos to Tableau Senturus, Inc. Page 1 Senturus Analytics Connector User Guide Cognos to Tableau 2019-2019 Senturus, Inc. Page 1 Overview This guide describes how the Senturus Analytics Connector is used from Tableau after it has been configured.

More information

Oracle Database 12c SQL Fundamentals

Oracle Database 12c SQL Fundamentals Course Overview This course takes a unique approach to SQL training in that it incorporates data modeling theory, relational database theory, graphical depictions of theoretical concepts and numerous examples

More information

Senturus Analytics Connector. User Guide Cognos to Power BI Senturus, Inc. Page 1

Senturus Analytics Connector. User Guide Cognos to Power BI Senturus, Inc. Page 1 Senturus Analytics Connector User Guide Cognos to Power BI 2019-2019 Senturus, Inc. Page 1 Overview This guide describes how the Senturus Analytics Connector is used from Power BI after it has been configured.

More information

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 3 Professional Program: Data Administration and Management MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9) AGENDA

More information

Oracle Syllabus Course code-r10605 SQL

Oracle Syllabus Course code-r10605 SQL Oracle Syllabus Course code-r10605 SQL Writing Basic SQL SELECT Statements Basic SELECT Statement Selecting All Columns Selecting Specific Columns Writing SQL Statements Column Heading Defaults Arithmetic

More information

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data 1 Writing Basic SQL SELECT Statements Objectives 1-2 Capabilities of SQL SELECT Statements 1-3 Basic SELECT Statement 1-4 Selecting All Columns 1-5 Selecting Specific Columns 1-6 Writing SQL Statements

More information

Topics Fundamentals of PL/SQL, Integration with PROIV SuperLayer and use within Glovia

Topics Fundamentals of PL/SQL, Integration with PROIV SuperLayer and use within Glovia Topics Fundamentals of PL/SQL, Integration with PROIV SuperLayer and use within Glovia 1. Creating a Database Alias 2. Introduction to SQL Relational Database Concept Definition of Relational Database

More information

GridDB Advanced Edition SQL reference

GridDB Advanced Edition SQL reference GMA022C1 GridDB Advanced Edition SQL reference Toshiba Solutions Corporation 2016 All Rights Reserved. Introduction This manual describes how to write a SQL command in the GridDB Advanced Edition. Please

More information

Chapter-14 SQL COMMANDS

Chapter-14 SQL COMMANDS Chapter-14 SQL COMMANDS What is SQL? Structured Query Language and it helps to make practice on SQL commands which provides immediate results. SQL is Structured Query Language, which is a computer language

More information

Relational Database Language

Relational Database Language DATA BASE MANAGEMENT SYSTEMS Unit IV Relational Database Language: Data definition in SQL, Queries in SQL, Insert, Delete and Update Statements in SQL, Views in SQL, Specifying General Constraints as Assertions,

More information

This course is aimed at those who need to extract information from a relational database system.

This course is aimed at those who need to extract information from a relational database system. (SQL) SQL Server Database Querying Course Description: This course is aimed at those who need to extract information from a relational database system. Although it provides an overview of relational database

More information

Teradata SQL Features Overview Version

Teradata SQL Features Overview Version Table of Contents Teradata SQL Features Overview Version 14.10.0 Module 0 - Introduction Course Objectives... 0-4 Course Description... 0-6 Course Content... 0-8 Module 1 - Teradata Studio Features Optimize

More information

GridDB Advanced Edition SQL reference

GridDB Advanced Edition SQL reference GMA022J4 GridDB Advanced Edition SQL reference Toshiba Digital Solutions Corporation 2017-2018 All Rights Reserved. Introduction This manual describes how to write a SQL command in the GridDB Advanced

More information

Oracle Database: Introduction to SQL Ed 2

Oracle Database: Introduction to SQL Ed 2 Oracle University Contact Us: +40 21 3678820 Oracle Database: Introduction to SQL Ed 2 Duration: 5 Days What you will learn This Oracle Database 12c: Introduction to SQL training helps you write subqueries,

More information

The SQL Guide to Pervasive PSQL. Rick F. van der Lans

The SQL Guide to Pervasive PSQL. Rick F. van der Lans The SQL Guide to Pervasive PSQL Rick F. van der Lans Copyright 2009 by R20/Consultancy All rights reserved; no part of this publication may be reproduced, stored in a retrieval system, or transmitted in

More information

Oracle Database 11g: SQL and PL/SQL Fundamentals

Oracle Database 11g: SQL and PL/SQL Fundamentals Oracle University Contact Us: +33 (0) 1 57 60 20 81 Oracle Database 11g: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn In this course, students learn the fundamentals of SQL and PL/SQL

More information

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model Database Design Section1 - Introduction 1-1 Introduction to the Oracle Academy o Give examples of jobs, salaries, and opportunities that are possible by participating in the Academy. o Explain how your

More information

Oracle Database Lite. SQL Reference Release 10.3 E

Oracle Database Lite. SQL Reference Release 10.3 E Oracle Database Lite SQL Reference Release 10.3 E12092-02 February 2010 Oracle Database Lite SQL Reference Release 10.3 E12092-02 Copyright 1997, 2010, Oracle and/or its affiliates. All rights reserved.

More information

Senturus Analytics Connector Version 3.0. User Guide. Senturus, Inc. 533 Airport Blvd. Suite 400 Burlingame CA P F

Senturus Analytics Connector Version 3.0. User Guide. Senturus, Inc. 533 Airport Blvd. Suite 400 Burlingame CA P F Senturus Analytics Connector Version 3.0 User Guide Senturus, Inc. 533 Airport Blvd. Suite 400 Burlingame CA 94010 P 888 601 6010 F 650 745 0640 Table of Contents 1. Install and Configure Senturus Analytics

More information

Topics - System Administration for Glovia

Topics - System Administration for Glovia Topics - System Administration for Glovia 1. Network Architecture Sample Network 2. glovia.com Technology Architecture Application Server Database Server Web Server 3. Operating System Architecture High

More information

Installation and Configuration Guide

Installation and Configuration Guide Senturus Analytics Connector Version 2.2 Installation and Configuration Guide Senturus Inc. 533 Airport Blvd. Suite 400 Burlingame CA 94010 P 888 601 6010 F 650 745 0640 2017 Senturus, Inc. Table of Contents

More information

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals NEW Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training delivers the fundamentals of SQL and PL/SQL along with the

More information

UNIT III INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL)

UNIT III INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) UNIT III INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) 3.1Data types 3.2Database language. Data Definition Language: CREATE,ALTER,TRUNCATE, DROP 3.3 Database language. Data Manipulation Language: INSERT,SELECT,UPDATE,DELETE

More information

Oracle Database: SQL and PL/SQL Fundamentals Ed 2

Oracle Database: SQL and PL/SQL Fundamentals Ed 2 Oracle University Contact Us: Local: 1800 103 4775 Intl: +91 80 67863102 Oracle Database: SQL and PL/SQL Fundamentals Ed 2 Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals

More information

INTRODUCTION TO MYSQL MySQL : It is an Open Source RDBMS Software that uses Structured Query Language. It is available free of cost. Key Features of MySQL : MySQL Data Types: 1. High Speed. 2. Ease of

More information

Installation and Configuration Guide

Installation and Configuration Guide Senturus Analytics Connector Version 2.2 Installation and Configuration Guide Senturus Inc 533 Airport Blvd. Suite 400 Burlingame CA 94010 P 888 601 6010 F 650 745 0640 Table of Contents 1. Install Senturus

More information

SQL FUNCTIONS. Prepared By:Dr. Vipul Vekariya.

SQL FUNCTIONS. Prepared By:Dr. Vipul Vekariya. SQL FUNCTIONS Prepared By:Dr. Vipul Vekariya. SQL FUNCTIONS Definition of Function Types of SQL Function Numeric Function String Function Conversion Function Date Function SQL Function Sub program of SQL

More information

DB2 SQL Class Outline

DB2 SQL Class Outline DB2 SQL Class Outline The Basics of SQL Introduction Finding Your Current Schema Setting Your Default SCHEMA SELECT * (All Columns) in a Table SELECT Specific Columns in a Table Commas in the Front or

More information

Oracle Database 10g: Introduction to SQL

Oracle Database 10g: Introduction to SQL ORACLE UNIVERSITY CONTACT US: 00 9714 390 9000 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database

More information

Oracle Database 10g: SQL Fundamentals I

Oracle Database 10g: SQL Fundamentals I Oracle Database 10g: SQL Fundamentals I Volume I Student Guide D17108GC11 Edition 1.1 August 2004 D39766 Author Nancy Greenberg Technical Contributors and Reviewers Wayne Abbott Christian Bauwens Perry

More information

Oracle Database 11g: SQL Fundamentals I

Oracle Database 11g: SQL Fundamentals I Oracle Database 11g: SQL Fundamentals I Volume I Student Guide D49996GC11 Edition 1.1 April 2009 D59980 Authors Puja Singh Brian Pottle Technical Contributors and Reviewers Claire Bennett Tom Best Purjanti

More information

Greenplum SQL Class Outline

Greenplum SQL Class Outline Greenplum SQL Class Outline The Basics of Greenplum SQL Introduction SELECT * (All Columns) in a Table Fully Qualifying a Database, Schema and Table SELECT Specific Columns in a Table Commas in the Front

More information

Writing PL/SQL Executable Statements. Copyright 2007, Oracle. All rights reserved.

Writing PL/SQL Executable Statements. Copyright 2007, Oracle. All rights reserved. What Will I Learn? In this lesson, you will learn to: Construct accurate variable assignment statements in PL/SQL Construct accurate statements using built-in SQL functions in PL/SQL Differentiate between

More information

AO3 - Version: 2. Oracle Database 11g SQL

AO3 - Version: 2. Oracle Database 11g SQL AO3 - Version: 2 Oracle Database 11g SQL Oracle Database 11g SQL AO3 - Version: 2 3 days Course Description: This course provides the essential SQL skills that allow developers to write queries against

More information

618 Index. BIT data type, 108, 109 BIT_LENGTH, 595f BIT VARYING data type, 108 BLOB data type, 108 Boolean data type, 109

618 Index. BIT data type, 108, 109 BIT_LENGTH, 595f BIT VARYING data type, 108 BLOB data type, 108 Boolean data type, 109 Index A abbreviations in field names, 22 in table names, 31 Access. See under Microsoft acronyms in field names, 22 in table names, 31 aggregate functions, 74, 375 377, 416 428. See also AVG; COUNT; COUNT(*);

More information

Lecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University

Lecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University Lecture 3 SQL Shuigeng Zhou September 23, 2008 School of Computer Science Fudan University Outline Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views

More information

What are temporary tables? When are they useful?

What are temporary tables? When are they useful? What are temporary tables? When are they useful? Temporary tables exists solely for a particular session, or whose data persists for the duration of the transaction. The temporary tables are generally

More information

arc tangent, 26 ASIN, 22t, 25 ATAN, 22t, 26 ATAN2, 22t, 26 ATANH, 22t, 26 AVG, 18t

arc tangent, 26 ASIN, 22t, 25 ATAN, 22t, 26 ATAN2, 22t, 26 ATANH, 22t, 26 AVG, 18t A ABS, 22t, 24 Access. See Microsoft Access ACOS, 22t, 24 Active Server Pages (ASP), 2, 153-154,, ADO/ODBC and, 140-142, -, ActiveX Data Objects. See ADO ADO/ODBC, 18, 132-142, 156 Active Server Pages

More information

Oracle Database 10g: SQL Fundamentals I

Oracle Database 10g: SQL Fundamentals I Oracle Database 10g: SQL Fundamentals I Student Guide Volume I D17108GC21 Edition 2.1 December 2006 D48183 Authors Chaitanya Koratamaddi Nancy Greenberg Technical Contributors and Reviewers Wayne Abbott

More information

TINYINT[(M)] [UNSIGNED] [ZEROFILL] A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.

TINYINT[(M)] [UNSIGNED] [ZEROFILL] A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255. MySQL: Data Types 1. Numeric Data Types ZEROFILL automatically adds the UNSIGNED attribute to the column. UNSIGNED disallows negative values. SIGNED (default) allows negative values. BIT[(M)] A bit-field

More information

@vmahawar. Agenda Topics Quiz Useful Links

@vmahawar. Agenda Topics Quiz Useful Links @vmahawar Agenda Topics Quiz Useful Links Agenda Introduction Stakeholders, data classification, Rows/Columns DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE CONSTRAINTS, DATA TYPES DML Data

More information

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1 SQL Fundamentals Chapter 3 Class 03: SQL Fundamentals 1 Class 03: SQL Fundamentals 2 SQL SQL (Structured Query Language): A language that is used in relational databases to build and query tables. Earlier

More information

Table of Contents. PDF created with FinePrint pdffactory Pro trial version

Table of Contents. PDF created with FinePrint pdffactory Pro trial version Table of Contents Course Description The SQL Course covers relational database principles and Oracle concepts, writing basic SQL statements, restricting and sorting data, and using single-row functions.

More information

Advanced SQL Tribal Data Workshop Joe Nowinski

Advanced SQL Tribal Data Workshop Joe Nowinski Advanced SQL 2018 Tribal Data Workshop Joe Nowinski The Plan Live demo 1:00 PM 3:30 PM Follow along on GoToMeeting Optional practice session 3:45 PM 5:00 PM Laptops available What is SQL? Structured Query

More information

Optional SQL Feature Summary

Optional SQL Feature Summary Optional SQL Feature Summary The following table lists all optional features included in the SQL standard, from SQL- 2003 to SQL-2016. It also indicates which features that are currently supported by Mimer

More information

Essential SQLite3. Section Title Page

Essential SQLite3. Section Title Page One Introduction to SQL 2 Definition of SQL 3 Definition of a Database 4 Two Database Tables 5 Three The SQLite Interface 10 Introduction 11 Running SQLite 12 DOS commands 14 Copying and Pasting 17 Exiting

More information

5. Single-row function

5. Single-row function 1. 2. Introduction Oracle 11g Oracle 11g Application Server Oracle database Relational and Object Relational Database Management system Oracle internet platform System Development Life cycle 3. Writing

More information

Oracle Developer Track Course Contents. Mr. Sandeep M Shinde. Oracle Application Techno-Functional Consultant

Oracle Developer Track Course Contents. Mr. Sandeep M Shinde. Oracle Application Techno-Functional Consultant Oracle Developer Track Course Contents Sandeep M Shinde Oracle Application Techno-Functional Consultant 16 Years MNC Experience in India and USA Trainer Experience Summary:- Sandeep M Shinde is having

More information

COURSE STUDENT LEARNING OUTCOMES: See attached or in course s learn.unm.edu

COURSE STUDENT LEARNING OUTCOMES: See attached or in course s learn.unm.edu Syllabus Online IT 222(CRN #43196) Data Base Management Systems Instructor: James Hart / hart56@unm.edu Office Room Number: B 123 Instructor's Campus Phone: 505.925.8720 / Mobile 505.239.3435 Office Hours:

More information

SAS 9.2 Table Server. TSPL Language Reference

SAS 9.2 Table Server. TSPL Language Reference SAS 9.2 Table Server TSPL Language Reference The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2009. SAS 9.2 Table Server: TSPL Language Reference. Cary, NC: SAS Institute

More information

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions.

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions. Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Re-accredited at the 'A' Grade Level by the NAAC and ISO 9001:2008 Certified CRISL rated

More information

Oracle 12C DBA Online Training. Course Modules of Oracle 12C DBA Online Training: 1 Oracle Database 12c: Introduction to SQL:

Oracle 12C DBA Online Training. Course Modules of Oracle 12C DBA Online Training: 1 Oracle Database 12c: Introduction to SQL: Course Modules of Oracle 12C DBA Online Training: 1 Oracle Database 12c: Introduction to SQL: A. Introduction Course Objectives, Course Agenda and Appendixes Used in this Course Overview of Oracle Database

More information

Relational Database Management Systems for Epidemiologists: SQL Part I

Relational Database Management Systems for Epidemiologists: SQL Part I Relational Database Management Systems for Epidemiologists: SQL Part I Outline SQL Basics Retrieving Data from a Table Operators and Functions What is SQL? SQL is the standard programming language to create,

More information

1) Introduction to SQL

1) Introduction to SQL 1) Introduction to SQL a) Database language enables users to: i) Create the database and relation structure; ii) Perform insertion, modification and deletion of data from the relationship; and iii) Perform

More information

Model Question Paper. Credits: 4 Marks: 140

Model Question Paper. Credits: 4 Marks: 140 Model Question Paper Subject Code: BT0075 Subject Name: RDBMS and MySQL Credits: 4 Marks: 140 Part A (One mark questions) 1. MySQL Server works in A. client/server B. specification gap embedded systems

More information

CS-201 Introduction to Programming with Java

CS-201 Introduction to Programming with Java CS-201 Introduction to Programming with Java California State University, Los Angeles Computer Science Department Lecture V: Mathematical Functions, Characters, and Strings Introduction How would you estimate

More information

Exact Numeric Data Types

Exact Numeric Data Types SQL Server Notes for FYP SQL data type is an attribute that specifies type of data of any object. Each column, variable and expression has related data type in SQL. You would use these data types while

More information

DB2 UDB: Application Programming

DB2 UDB: Application Programming A ABS or ABSVAL... 4:19 Access Path - Determining... 10:8 Access Strategies... 9:3 Additional Facts About Data Types... 5:18 Aliases... 1:13 ALL, ANY, SOME Operator... 3:21 AND... 3:12 Arithmetic Expressions...

More information

SQL is an English like language consisting of commands to store, retrieve, maintain & regulate access to your database.

SQL is an English like language consisting of commands to store, retrieve, maintain & regulate access to your database. SQL SQL is an English like language consisting of commands to store, retrieve, maintain & regulate access to your database. SQL*Plus SQL*Plus is an application that recognizes & executes SQL commands &

More information

Index. NOTE: Boldface numbers indicate illustrations or code listing; t indicates a table. 341

Index. NOTE: Boldface numbers indicate illustrations or code listing; t indicates a table. 341 A access paths, 31 optimizing SQL and, 135, 135 access types, restricting SQL statements, JDBC setup and, 36-37, 37 accessing iseries data from a PC, 280-287, 280 accumulate running totals, 192-197, 193,

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle Database: Introduction to SQL What you will learn Understanding the basic concepts of relational databases ensure refined code by developers. This course helps the participants to write subqueries,

More information

Lab # 4. Data Definition Language (DDL)

Lab # 4. Data Definition Language (DDL) Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Lab # 4 Data Definition Language (DDL) Eng. Haneen El-Masry November, 2014 2 Objective To be familiar with

More information

Using SQL with SQL Developer 18.2

Using SQL with SQL Developer 18.2 One Introduction to SQL 2 - Definition 3 - Usage of SQL 4 - What is SQL used for? 5 - Who uses SQL? 6 - Definition of a Database 7 - What is SQL Developer? 8 Two The SQL Developer Interface 9 - Introduction

More information

MySQL 5.0 Certification Study Guide

MySQL 5.0 Certification Study Guide MySQL 5.0 Certification Study Guide Paul DuBois, Stefan Hinz, and Carsten Pedersen MySQC Press 800 East 96th Street, Indianapolis, Indiana 46240 USA Table of Contents Introduction 1 About This Book 1 Sample

More information

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals Oracle University Contact Us: 001-855-844-3881 & 001-800-514-06-9 7 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training

More information

MariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney.

MariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney. MariaDB Crash Course Ben Forta A Addison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid Cape Town Sydney Tokyo Singapore Mexico City

More information

DB2 Function Conversion for Sybase ASE Users

DB2 Function Conversion for Sybase ASE Users DB2 Function Conversion for Sybase ASE Users ChangSung KANG, Kitty Lau IMTE Version 1.2 Date: July-01-2011 Page:1 Version: 1.1 Document History Version Date Author Comment Authorization 1.0 07/01/2011

More information

Advanced Security in Sybase IQ. Sybase IQ 15.3

Advanced Security in Sybase IQ. Sybase IQ 15.3 Sybase IQ 15.3 DOCUMENT ID: DC01015-01-1530-01 LAST REVISED: May 2011 Copyright 2011 by Sybase, Inc. All rights reserved. This publication pertains to Sybase software and to any subsequent release until

More information

20461: Querying Microsoft SQL Server 2014 Databases

20461: Querying Microsoft SQL Server 2014 Databases Course Outline 20461: Querying Microsoft SQL Server 2014 Databases Module 1: Introduction to Microsoft SQL Server 2014 This module introduces the SQL Server platform and major tools. It discusses editions,

More information

T-SQL Training: T-SQL for SQL Server for Developers

T-SQL Training: T-SQL for SQL Server for Developers Duration: 3 days T-SQL Training Overview T-SQL for SQL Server for Developers training teaches developers all the Transact-SQL skills they need to develop queries and views, and manipulate data in a SQL

More information

Chapter 4: SQL. Basic Structure

Chapter 4: SQL. Basic Structure Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Joined Relations Data Definition Language Embedded SQL

More information

SQL OVERVIEW. CS121: Relational Databases Fall 2017 Lecture 4

SQL OVERVIEW. CS121: Relational Databases Fall 2017 Lecture 4 SQL OVERVIEW CS121: Relational Databases Fall 2017 Lecture 4 SQL 2 SQL = Structured Query Language Original language was SEQUEL IBM s System R project (early 1970 s) Structured English Query Language Caught

More information

2 PL/SQL - fundamentals Variables and Constants Operators SQL in PL/SQL Control structures... 7

2 PL/SQL - fundamentals Variables and Constants Operators SQL in PL/SQL Control structures... 7 Table of Contents Spis treści 1 Introduction 1 2 PLSQL - fundamentals 1 2.1 Variables and Constants............................ 2 2.2 Operators.................................... 5 2.3 SQL in PLSQL.................................

More information

Database Database administration

Database Database administration System i Database Database administration Version 6 Release 1 System i Database Database administration Version 6 Release 1 Note Before using this information and the product it supports, read the information

More information

Listing of SQLSTATE values

Listing of SQLSTATE values Listing of values 1 of 28 5/15/2008 11:28 AM Listing of values The tables in this topic provide descriptions of codes that can be returned to applications by DB2 UDB for iseries. The tables include values,

More information

Querying Data with Transact SQL

Querying Data with Transact SQL Course 20761A: Querying Data with Transact SQL Course details Course Outline Module 1: Introduction to Microsoft SQL Server 2016 This module introduces SQL Server, the versions of SQL Server, including

More information

AVANTUS TRAINING PTE LTD

AVANTUS TRAINING PTE LTD [MS20461]: Querying Microsoft SQL Server 2014 Length : 5 Days Audience(s) : IT Professionals Level : 300 Technology : SQL Server Delivery Method : Instructor-led (Classroom) Course Overview This 5-day

More information

SQL. - single row functions - Database Design ( 데이터베이스설계 ) JUNG, Ki-Hyun ( 정기현 )

SQL. - single row functions - Database Design ( 데이터베이스설계 ) JUNG, Ki-Hyun ( 정기현 ) SQL Database Design ( 데이터베이스설계 ) - single row functions - JUNG, Ki-Hyun ( 정기현 ) 1 SQL Functions Input Function Output Function performs action that defined already before execution 2 Two Types of SQL Functions

More information

Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition

Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition Language 4.1 Schema Used in Examples

More information

Oracle SQL Developer. Oracle TimesTen In-Memory Database Support User's Guide Release 4.0 E

Oracle SQL Developer. Oracle TimesTen In-Memory Database Support User's Guide Release 4.0 E Oracle SQL Developer Oracle TimesTen In-Memory Database Support User's Guide Release 4.0 E39882-02 December 2013 Oracle SQL Developer Oracle TimesTen In-Memory Database Support User's Guide, Release 4.0

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: (+202) 35 35 02 54 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn View a newer version of this course This Oracle Database: Introduction to SQL

More information

Lecture 07. Spring 2018 Borough of Manhattan Community College

Lecture 07. Spring 2018 Borough of Manhattan Community College Lecture 07 Spring 2018 Borough of Manhattan Community College 1 SQL Identifiers SQL identifiers are used to identify objects in the database, such as table names, view names, and columns. The ISO standard

More information

Oracle Database: Introduction to SQL/PLSQL Accelerated

Oracle Database: Introduction to SQL/PLSQL Accelerated Oracle University Contact Us: Landline: +91 80 67863899 Toll Free: 0008004401672 Oracle Database: Introduction to SQL/PLSQL Accelerated Duration: 5 Days What you will learn This Introduction to SQL/PLSQL

More information

BigFix Inspector Library

BigFix Inspector Library BigFix Inspector Library Core Inspectors Compatible with BES 8.0 November 23, 2010 2010 BigFix, Inc. All rights reserved. BigFix, Fixlet, Relevance Engine, Powered by BigFix and related BigFix logos are

More information

20761 Querying Data with Transact SQL

20761 Querying Data with Transact SQL Course Overview The main purpose of this course is to give students a good understanding of the Transact-SQL language which is used by all SQL Server-related disciplines; namely, Database Administration,

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: +27 (0)11 319-4111 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn This Oracle Database: Introduction to SQL training helps you write subqueries,

More information

Using SQL with SQL Developer Part I

Using SQL with SQL Developer Part I One Introduction to SQL 2 Definition 3 Usage of SQL 4 What is SQL used for? 5 Who uses SQL? 6 Definition of a Database 7 What is SQL Developer? 8 Two The SQL Developer Interface 9 Introduction 10 Connections

More information

Built-in SQL Functions. Chapter 5

Built-in SQL Functions. Chapter 5 Built-in SQL Functions Chapter 5 Type of Functions Character Functions returning character values returning numeric values Numeric Functions Date Functions Conversion Functions Group Functions Error Reporting

More information

SQL Interview Questions

SQL Interview Questions SQL Interview Questions SQL stands for Structured Query Language. It is used as a programming language for querying Relational Database Management Systems. In this tutorial, we shall go through the basic

More information

Using SQL with SQL Developer 18.2 Part I

Using SQL with SQL Developer 18.2 Part I One Introduction to SQL 2 - Definition 3 - Usage of SQL 4 - What is SQL used for? 5 - Who uses SQL? 6 - Definition of a Database 7 - What is SQL Developer? 8 Two The SQL Developer Interface 9 - Introduction

More information

Silberschatz, Korth and Sudarshan See for conditions on re-use

Silberschatz, Korth and Sudarshan See   for conditions on re-use Chapter 3: SQL Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 3: SQL Data Definition Basic Query Structure Set Operations Aggregate Functions Null Values Nested

More information

COPYRIGHTED MATERIAL. Index SYMBOLS AND NUMERICS. Index

COPYRIGHTED MATERIAL. Index SYMBOLS AND NUMERICS. Index Index Index SYMBOLS AND NUMERICS + (addition operator), 272 (angle brackets), 15 * (asterisk), 233 234, 354 355, 669 @ (at symbol), 241, 555 \. (backslash, period), 445 > (bitwise shift right operator),

More information

Index. Bitmap Heap Scan, 156 Bitmap Index Scan, 156. Rahul Batra 2018 R. Batra, SQL Primer,

Index. Bitmap Heap Scan, 156 Bitmap Index Scan, 156. Rahul Batra 2018 R. Batra, SQL Primer, A Access control, 165 granting privileges to users general syntax, GRANT, 170 multiple privileges, 171 PostgreSQL, 166 169 relational databases, 165 REVOKE command, 172 173 SQLite, 166 Aggregate functions

More information

Creating and Managing Tables Schedule: Timing Topic

Creating and Managing Tables Schedule: Timing Topic 9 Creating and Managing Tables Schedule: Timing Topic 30 minutes Lecture 20 minutes Practice 50 minutes Total Objectives After completing this lesson, you should be able to do the following: Describe the

More information

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation Basic SQL Dr Fawaz Alarfaj Al Imam Mohammed Ibn Saud Islamic University ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation MIDTERM EXAM 2 Basic

More information

"Charting the Course to Your Success!" MOC D Querying Microsoft SQL Server Course Summary

Charting the Course to Your Success! MOC D Querying Microsoft SQL Server Course Summary Course Summary Description This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL queries for Microsoft SQL Server 2014. This course is the foundation

More information

SQL Structured Query Language (1/2)

SQL Structured Query Language (1/2) Oracle Tutorials SQL Structured Query Language (1/2) Giacomo Govi IT/ADC Overview Goal: Learn the basic for interacting with a RDBMS Outline SQL generalities Available statements Restricting, Sorting and

More information