100 SQL query Tips and Techniques

sql query performance tips and tricks and how to execute sql command in entity framework and how to learn sql commands and how to run sql commands online
OliviaCutts Profile Pic
Published Date:01-08-2017
Your Website URL(Optional)
Structured Query Language (SQL) SQL Commands, Tips & Structure Visit the Cultural View of Technology SQL Tutorial Page for videos and exercises PDF generated using the open source mwlib toolkit. See http://code.pediapress.com/ for more information. PDF generated at: Thu, 17 Jun 2010 01:11:48 UTC SQL 1 SQL Paradigm Multi-paradigm Appeared in 1974 Designed by Donald D. Chamberlin Raymond F. Boyce Developer IBM Stable release SQL:2008 (2008) Typing discipline Static, strong Major implementations Many Dialects SQL-86, SQL-89, SQL-92, SQL:1999, SQL:2003, SQL:2008 Influenced by Datalog Influenced Agena, CQL, LINQ, Windows PowerShell OS Cross-platform 1 SQL (officially pronounced /ˌɛskjuːˈɛl/ like "S-Q-L" but is often pronounced /ˈsiːkwəl/ like "Sequel"), often 2 3 referred to as Structured Query Language, is a database computer language designed for managing data in relational database management systems (RDBMS), and originally based upon relational algebra. Its scope includes data query and update, schema creation and modification, and data access control. SQL was one of the first languages for Edgar F. Codd's relational model in his influential 1970 paper, "A Relational Model of Data for Large 4 2 5 Shared Data Banks" and became the most widely used language for relational databases. ANSI SQL is a Turing complete programming language. History SQL was developed at IBM by Donald D. Chamberlin and Raymond F. Boyce in the early 1970s. This version, initially called SEQUEL, was designed to manipulate and retrieve data stored in IBM's original relational database management system, System R, which a group at IBM San Jose Research Laboratory had developed during the 6 1970s. The acronym SEQUEL was later changed to SQL because "SEQUEL" was a trademark of the UK-based 7 Hawker Siddeley aircraft company. The first Relational Database Management System (RDBMS) was RDMS, developed at MIT in the early 1970s, soon followed by Ingres, developed in 1974 at U.C. Berkeley. Ingres implemented a query language known as 7 QUEL, which was later supplanted in the marketplace by SQL. In the late 1970s, Relational Software, Inc. (now Oracle Corporation) saw the potential of the concepts described by Codd, Chamberlin, and Boyce and developed their own SQL-based RDBMS with aspirations of selling it to the U.S. Navy, Central Intelligence Agency, and other U.S. government agencies. In the summer of 1979, Relational Software, Inc. introduced the first commercially available implementation of SQL, Oracle V2 (Version2) for VAX computers. Oracle V2 beat IBM's release of the System/38 RDBMS to market by a few weeks. After testing SQL at customer test sites to determine the usefulness and practicality of the system, IBM began developing commercial products based on their System R prototype including System/38, SQL/DS, and DB2, which 8 were commercially available in 1979, 1981, and 1983, respectively. Common criticisms of SQL include a lack of cross-platform portability between vendors, inappropriate handling of missing data (see Null (SQL)), and unnecessarily complex and occasionally ambiguous language grammar and semantics . It also lacks the rigour of more formal languages such as relational algebra . SQL 2 Language elements The SQL language is sub-divided into several language elements, including: • Clauses, which are in some cases optional, constituent components of statements and 9 queries. • Expressions which can produce either scalar This chart shows several of the SQL language elements that compose a values or tables consisting of columns and single statement. rows of data. • Predicates which specify conditions that can be evaluated to SQL three-valued logic (3VL) Boolean truth values and which are used to limit the effects of statements and queries, or to change program flow. • Queries which retrieve data based on specific criteria. • Statements which may have a persistent effect on schemas and data, or which may control transactions, program flow, connections, sessions, or diagnostics. • SQL statements also include the semicolon (";") statement terminator. Though not required on every platform, it is defined as a standard part of the SQL grammar. • Insignificant whitespace is generally ignored in SQL statements and queries, making it easier to format SQL code for readability. Queries The most common operation in SQL is the query, which is performed with the declarative SELECT statement. SELECT retrieves data from one or more tables, or expressions. Standard SELECT statements have no persistent effects on the database. Some non-standard implementations of SELECT can have persistent effects, such as the 10 SELECT INTO syntax that exists in some databases. Queries allow the user to describe desired data, leaving the database management system (DBMS) responsible for planning, optimizing, and performing the physical operations necessary to produce that result as it chooses. A query includes a list of columns to be included in the final result immediately following the SELECT keyword. An asterisk ("") can also be used to specify that the query should return all columns of the queried tables. SELECT is the most complex statement in SQL, with optional keywords and clauses that include: • The FROM clause which indicates the table(s) from which data is to be retrieved. The FROM clause can include optional JOIN subclauses to specify the rules for joining tables. • The WHERE clause includes a comparison predicate, which restricts the rows returned by the query. The WHERE clause eliminates all rows from the result set for which the comparison predicate does not evaluate to True. • The GROUP BY clause is used to project rows having common values into a smaller set of rows. GROUP BY is often used in conjunction with SQL aggregation functions or to eliminate duplicate rows from a result set. The WHERE clause is applied before the GROUP BY clause. • The HAVING clause includes a predicate used to filter rows resulting from the GROUP BY clause. Because it acts on the results of the GROUP BY clause, aggregation functions can be used in the HAVING clause predicate. • The ORDER BY clause identifies which columns are used to sort the resulting data, and in which direction they should be sorted (options are ascending or descending). Without an ORDER BY clause, the order of rows returned by an SQL query is undefined. The following is an example of a SELECT query that returns a list of expensive books. The query retrieves all rows from the Book table in which the price column contains a value greater than 100.00. The result is sorted in ascending order by title. The asterisk () in the select list indicates that all columns of the Book table should be included in the SQL 3 result set. SELECT FROM Book WHERE price 100.00 ORDER BY title; The example below demonstrates a query of multiple tables, grouping, and aggregation, by returning a list of books and the number of authors associated with each book. SELECT Book.title, count() AS Authors FROM Book JOIN Book_author ON Book.isbn = Book_author.isbn GROUP BY Book.title; Example output might resemble the following: Title Authors - SQL Examples and Guide 4 The Joy of SQL 1 An Introduction to SQL 2 Pitfalls of SQL 1 Under the precondition that isbn is the only common column name of the two tables and that a column named title only exists in the Books table, the above query could be rewritten in the following form: SELECT title, count() AS Authors FROM Book NATURAL JOIN Book_author GROUP BY title; However, many vendors either do not support this approach, or require certain column naming conventions in order for natural joins to work effectively. SQL includes operators and functions for calculating values on stored values. SQL allows the use of expressions in the select list to project data, as in the following example which returns a list of books that cost more than 100.00 with an additional sales_tax column containing a sales tax figure calculated at 6% of the price. SELECT isbn, title, price, price 0.06 AS sales_tax FROM Book WHERE price 100.00 ORDER BY title; SQL 4 Null and three-valued logic (3VL) The idea of Null was introduced into SQL to handle missing information in the relational model. The introduction of Null (or Unknown) along with True and False is the foundation of three-valued logic. Null does not have a value (and is not a member of any data domain) but is rather a placeholder or “mark” for missing information. Therefore 11 comparisons with Null can never result in either True or False but always in the third logical result, Unknown. SQL uses Null to handle missing information. It supports three-valued logic (3VL) and the rules governing SQL 12 three-valued logic (3VL) are shown below (p and q represent logical states). The word NULL is also a reserved keyword in SQL, used to identify the Null special marker. Additionally, since SQL operators return Unknown when comparing anything with Null, SQL provides two 13 Null-specific comparison predicates: The IS NULL and IS NOT NULL test whether data is or is not Null. Note that SQL returns only results for which the WHERE clause returns a value of True. I.e., it excludes results with values of False, but also those whose value is Unknown. p AND q p p OR q p p NOT p p = q p True False Unknown True False Unknown True False True False Unknown q True True False Unknown q True True True True False True q True True False Unknown False False False False False True False Unknown Unknown Unknown False False True Unknown Unknown Unknown False Unknown Unknown True Unknown Unknown Unknown Unknown Unknown Unknown Universal quantification is not explicitly supported by SQL, and must be worked out as a negated existential 14 15 16 quantification. There is also the "row value expression IS DISTINCT FROM row value expression" infixed comparison operator which returns TRUE unless both operands are equal or both are NULL. Likewise, IS NOT DISTINCT FROM is defined as "NOT (row value expression IS DISTINCT FROM row value expression") Data manipulation The Data Manipulation Language (DML) is the subset of SQL used to add, update and delete data: • INSERT adds rows (formally tuples) to an existing table, e.g.,: INSERT INTO My_table (field1, field2, field3) VALUES ('test', 'N', NULL); • UPDATE modifies a set of existing table rows, e.g.,: UPDATE My_table SET field1 = 'updated value' WHERE field2 = 'N'; • DELETE removes existing rows from a table, e.g.,: DELETE FROM My_table WHERE field2 = 'N'; • TRUNCATE deletes all data from a table in a very fast way. It usually implies a subsequent COMMIT operation. SQL 5 • MERGE is used to combine the data of multiple tables. It combines the INSERT and UPDATE elements. It is defined in the SQL:2003 standard; prior to that, some databases provided similar functionality via different syntax, sometimes called "upsert". Transaction controls Transactions, if available, wrap DML operations: • START TRANSACTION (or BEGIN WORK, or BEGIN TRANSACTION, depending on SQL dialect) mark the start of a database transaction, which either completes entirely or not at all. • SAVE TRANSACTION (or SAVEPOINT ) save the state of the database at the current point in transaction CREATE TABLE tbl_1(id int); INSERT into tbl_1(id) value(1); INSERT into tbl_1(id) value(2); COMMIT; UPDATE tbl_1 SET id=200 WHERE id=1; SAVEPOINT id-1upd; UPDATE tbl_1 SET id=1000 WHERE id=2; ROLLBACK to id-1upd; SELECT id from tbl_1; • COMMIT causes all data changes in a transaction to be made permanent. • ROLLBACK causes all data changes since the last COMMIT or ROLLBACK to be discarded, leaving the state of the data as it was prior to those changes. Once the COMMIT statement completes, the transaction's changes cannot be rolled back. COMMIT and ROLLBACK terminate the current transaction and release data locks. In the absence of a START TRANSACTION or similar statement, the semantics of SQL are implementation-dependent. Example: A classic bank transfer of funds transaction. START TRANSACTION; UPDATE Account SET amount=amount-200 WHERE account_number=1234; UPDATE Account SET amount=amount+200 WHERE account_number=2345; IF ERRORS=0 COMMIT; IF ERRORS0 ROLLBACK; Data definition The Data Definition Language (DDL) manages table and index structure. The most basic items of DDL are the CREATE, ALTER, RENAME, DROP and TRUNCATE statements: • CREATE creates an object (a table, for example) in the database. • DROP deletes an object in the database, usually irretrievably. • ALTER modifies the structure of an existing object in various ways—for example, adding a column to an existing table. Example: CREATE TABLE My_table ( my_field1 INT, my_field2 VARCHAR(50), my_field3 DATE NOT NULL, SQL 6 PRIMARY KEY (my_field1, my_field2) ); Data types Each column in an SQL table declares the type(s) that column may contain. ANSI SQL includes the following 17 datatypes. Character strings • CHARACTER(n) or CHAR(n) — fixed-width n-character string, padded with spaces as needed • CHARACTER VARYING(n) or VARCHAR(n) — variable-width string with a maximum size of n characters • NATIONAL CHARACTER(n) or NCHAR(n) — fixed width string supporting an international character set • NATIONAL CHARACTER VARYING(n) or NVARCHAR(n) — variable-width NCHAR string Bit strings • BIT(n) — an array of n bits • BIT VARYING(n) — an array of up to n bits Numbers • INTEGER and SMALLINT • FLOAT, REAL and DOUBLE PRECISION • NUMERIC(precision, scale) or DECIMAL(precision, scale) SQL provides a function to round numerics or dates, called TRUNC (in Informix, DB2, PostgreSQL, Oracle and 18 MySQL) or ROUND (in Informix, Sybase, Oracle, PostgreSQL and Microsoft SQL Server) Date and time • DATE — for date values (e.g., 2010-05-30) • TIME — for time values (e.g., 14:55:37). The granularity of the time value is usually a tick (100 nanoseconds). • TIME WITH TIME ZONE or TIMESTAMP — the same as TIME, but including details about the time zone in question. • TIMESTAMP — This is a DATE and a TIME put together in one variable (e.g., 2010-05-30 14:55:37). • TIMESTAMP WITH TIME ZONE or TIMESTAMPTZ — the same as TIMESTAMP, but including details about the time zone in question. SQL provides several functions for generating a date / time variable out of a date / time string (TO_DATE, TO_TIME, TO_TIMESTAMP), as well as for extracting the respective members (seconds, for instance) of such variables. The current system date / time of the database server can be called by using functions like NOW. Data control The Data Control Language (DCL) authorizes users and groups of users to access and manipulate data. Its two main statements are: • GRANT authorizes one or more users to perform an operation or a set of operations on an object. • REVOKE eliminates a grant, which may be the default grant. Example: GRANT SELECT, UPDATE ON My_table TO some_user, another_user; SQL 7 REVOKE SELECT, UPDATE ON My_table FROM some_user, another_user; Procedural extensions SQL is designed for a specific purpose: to query data contained in a relational database. SQL is a set-based, declarative query language, not an imperative language such as C or BASIC. However, there are extensions to Standard SQL which add procedural programming language functionality, such as control-of-flow constructs. These are: Source Common Full Name Name ANSI/ISO Standard SQL/PSM SQL/Persistent Stored Modules Interbase/ PSQL Procedural SQL Firebird IBM SQL PL SQL Procedural Language (implements SQL/PSM) Microsoft/ T-SQL Transact-SQL Sybase Mimer SQL SQL/PSM SQL/Persistent Stored Module (implements SQL/PSM) MySQL SQL/PSM SQL/Persistent Stored Module (implements SQL/PSM) Oracle PL/SQL Procedural Language/SQL (based on Ada) PostgreSQL PL/pgSQL Procedural Language/PostgreSQL Structured Query Language (based on Oracle PL/SQL) PostgreSQL PL/PSM Procedural Language/Persistent Stored Modules (implements SQL/PSM) In addition to the standard SQL/PSM extensions and proprietary SQL extensions, procedural and object-oriented programmability is available on many SQL platforms via DBMS integration with other languages. The SQL standard defines SQL/JRT extensions (SQL Routines and Types for the Java Programming Language) to support Java code in SQL databases. SQL Server 2005 uses the SQLCLR (SQL Server Common Language Runtime) to host managed .NET assemblies in the database, while prior versions of SQL Server were restricted to using unmanaged extended stored procedures which were primarily written in C. Other database platforms, like MySQL and Postgres, allow functions to be written in a wide variety of languages including Perl, Python, Tcl, and C. Criticisms of SQL SQL is a declarative computer language for use with relational databases. Interestingly, many of the original SQL features were inspired by, but violated, the semantics of the relational model and its tuple calculus realization. Recent extensions to SQL achieved relational completeness, but have worsened the violations, as documented in The Third Manifesto. Practical criticisms of SQL include: • Implementations are inconsistent and, usually, incompatible between vendors. In particular date and time syntax, string concatenation, nulls, and comparison case sensitivity vary from vendor to vendor. • The language makes it too easy to do a Cartesian join (joining all possible combinations), which results in "run- away" result sets when WHERE clauses are mistyped. Cartesian joins are so rarely used in practice that requiring an explicit CARTESIAN keyword may be warranted. (SQL 1992 introduced the CROSS JOIN keyword that allows the user to make clear that a Cartesian join is intended, but the shorthand "comma-join" with no predicate is still acceptable syntax, which still invites the same mistake.) SQL 8 • It is also possible to misconstruct a WHERE on an update or delete, thereby affecting more rows in a table than desired. (A work-around is to use transactions or habitually type in the WHERE clause first, then fill in the rest later.) • The grammar of SQL is perhaps unnecessarily complex, borrowing a COBOL-like keyword approach, when a function-influenced syntax could result in more re-use of fewer grammar and syntax rules. Cross-vendor portability Popular implementations of SQL commonly omit support for basic features of Standard SQL, such as the DATE or TIME data types. As a result, SQL code can rarely be ported between database systems without modifications. There are several reasons for this lack of portability between database systems: • The complexity and size of the SQL standard means that most implementors do not support the entire standard. • The standard does not specify database behavior in several important areas (e.g., indexes, file storage...), leaving implementations to decide how to behave. • The SQL standard precisely specifies the syntax that a conforming database system must implement. However, the standard's specification of the semantics of language constructs is less well-defined, leading to ambiguity. • Many database vendors have large existing customer bases; where the SQL standard conflicts with the prior behavior of the vendor's database, the vendor may be unwilling to break backward compatibility. • Software vendors often desire to create incompatibilities with other products, as it provides a strong incentive for their existing users to remain loyal (see vendor lock-in). Standardization 19 SQL was adopted as a standard by the American National Standards Institute (ANSI) in 1986 as SQL-86 and International Organization for Standardization (ISO) in 1987. The original SQL standard declared that the official 2 20 pronunciation for SQL is "es queue el". Many English-speaking database professionals still use the nonstandard pronunciation /ˈsiːkwəl/ (like the word "sequel"). Until 1996, the National Institute of Standards and Technology (NIST) data management standards program certified 21 SQL DBMS compliance with the SQL standard. Vendors now self-certify the compliance of their products. The SQL standard has gone through a number of revisions, as shown below: Year Name Alias Comments 1986 SQL-86 SQL-87 First formalized by ANSI. 1989 SQL-89 FIPS Minor revision, adopted as FIPS 127-1. 127-1 1992 SQL-92 SQL2, Major revision (ISO 9075), Entry Level SQL-92 adopted as FIPS 127-2. FIPS 127-2 1999 SQL:1999 SQL3 Added regular expression matching, recursive queries, triggers, support for procedural and control-of-flow statements, non-scalar types, and some object-oriented features. 2003 SQL:2003 Introduced XML-related features, window functions, standardized sequences, and columns with auto-generated values (including identity-columns). 2006 SQL:2006 ISO/IEC 9075-14:2006 defines ways in which SQL can be used in conjunction with XML. It defines ways of importing and storing XML data in an SQL database, manipulating it within the database and publishing both XML and conventional SQL-data in XML form. In addition, it enables applications to integrate into their SQL code the use of XQuery, the XML Query Language published by the World Wide Web Consortium (W3C), to concurrently access ordinary SQL-data and XML documents. SQL 9 2008 SQL:2008 Legalizes ORDER BY outside cursor definitions. Adds INSTEAD OF triggers. Adds the TRUNCATE 22 statement. Interested parties may purchase SQL standards documents from ISO or ANSI. A draft of SQL:2008 is freely 23 available as a zip archive. Standard structure The SQL standard is divided into several parts, including: SQL Framework, provides logical concept SQL/Foundation, defined in ISO/IEC 9075, Part 2. This part of the standard contains the most central elements of the language. It consists of both mandatory and optional features. The SQL/Bindings, specifies how SQL is to be bound to variable host languages,excluding Java. The SQL/CLI, or Call-Level Interface, part is defined in ISO/IEC 9075, Part 3. SQL/CLI defines common interfacing components (structures and procedures) that can be used to execute SQL statements from applications written in other programming languages. SQL/CLI is defined in such a way that SQL statements and SQL/CLI procedure calls are treated as separate from the calling application's source code. Open Database Connectivity is a well-known superset of SQL/CLI. This part of the standard consists solely of mandatory features. The SQL/PSM, or Persistent Stored Modules, part is defined by ISO/IEC 9075, Part 4. SQL/PSM standardizes procedural extensions for SQL, including flow of control, condition handling, statement condition signals and resignals, cursors and local variables, and assignment of expressions to variables and parameters. In addition, SQL/PSM formalizes declaration and maintenance of persistent database language routines (e.g., "stored procedures"). This part of the standard consists solely of optional features. The SQL/MED, or Management of External Data, part is defined by ISO/IEC 9075, Part 9. SQL/MED provides extensions to SQL that define foreign-data wrappers and datalink types to allow SQL to manage external data. External data is data that is accessible to, but not managed by, an SQL-based DBMS. This part of the standard consists solely of optional features. The SQL/OLB, or Object Language Bindings, part is defined by ISO/IEC 9075, Part 10. SQL/OLB defines the syntax and symantics of SQLJ, which is SQL embedded in Java. The standard also describes mechanisms to ensure binary portability of SQLJ applications, and specifies various Java packages and their contained classes. This part of the standard consists solely of optional features. The SQL/MM (Multimedia), This extends SQL to deal intelligently with large,complex and sometimes streaming items of data, such as video,audio and spatial data. The SQL/Schemata, or Information and Definition Schemas, part is defined by ISO/IEC 9075, Part 11. SQL/Schemata defines the Information Schema and Definition Schema, providing a common set of tools to make SQL databases and objects self-describing. These tools include the SQL object identifier, structure and integrity constraints, security and authorization specifications, features and packages of ISO/IEC 9075, support of features provided by SQL-based DBMS implementations, SQL-based DBMS implementation information and sizing items, 24 and the values supported by the DBMS implementations. This part of the standard contains both mandatory and optional features. The SQL/JRT, or SQL Routines and Types for the Java Programming Language, part is defined by ISO/IEC 9075, Part 13. SQL/JRT specifies the ability to invoke static Java methods as routines from within SQL applications. It also calls for the ability to use Java classes as SQL structured user-defined types. This part of the standard consists solely of optional features. The SQL/XML, or XML-Related Specifications, part is defined by ISO/IEC 9075, Part 14. SQL/XML specifies SQL-based extensions for using XML in conjunction with SQL. The XML data type is introduced, as well as several SQL 10 routines, functions, and XML-to-SQL data type mappings to support manipulation and storage of XML in an SQL database. This part of the standard consists solely of optional features. Alternatives to SQL A distinction should be made between alternatives to relational query languages and alternatives to SQL. Below are proposed relational alternatives to SQL. See navigational database for alternatives to relational: • .QL - object-oriented Datalog • 4D Query Language (4D QL) • Datalog • Hibernate Query Language (HQL) - A Java-based tool that uses modified SQL • HTSQL - URL based query method • IBM Business System 12 (IBM BS12) - one of the first fully relational database management systems, introduced in 1982 • ISBL • Java Persistence Query Language (JPQL) - The query language used by the Java Persistence API in Java EE5 • LINQ • Object Query Language • QBE (Query By Example) created by Moshè Zloof, IBM 1977 • Quel introduced in 1974 by the U.C. Berkeley Ingres project. • Tutorial D • XQuery See also • Comparison of object-relational database management systems • Comparison of relational database management systems • D (data language specification) • D4 (programming language) (an implementation of D) • Hierarchical model • List of relational database management systems • MUMPS • Search suggest drop-down list • NoSQL References 1 Beaulieu, Alan (April 2009). Mary E. Treseler. ed. Learning SQL (2nd ed.). Sebastapol, CA, USA: O'Reilly. ISBN 978-0-596-52083-0. 2 Chapple, Mike. "SQL Fundamentals" (http://databases.about.com/od/sql/a/sqlfundamentals.htm). About.com: Databases. About.com. . Retrieved 2009-01-28. 3 Connolly, Thomas. Database Systems (2nd ed.). Addison-Wesley. p. 384. ISBN 0-201-34287-1. 4 Codd, E.F. (June 1970). "A Relational Model of Data for Large Shared Data Banks" (http://www.acm.org/classics/nov95/toc.html). Communications of the ACM (Association for Computing Machinery) 13 (6): 377–387. doi:10.1145/362384.362685. . Retrieved 2007-06-09. 5 "Structured Query Language (SQL)" (http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb. admin.doc/doc/c0004100.htm). International Business Machines. October 27, 2006. . Retrieved 2007-06-10. 6 Chamberlin, Donald D.; Boyce, Raymond F. (1974). "SEQUEL: A Structured English Query Language" (http://www.almaden.ibm.com/ cs/people/chamberlin/sequel-1974.pdf) (PDF). Proceedings of the 1974 ACM SIGFIDET Workshop on Data Description, Access and Control (Association for Computing Machinery): 249–264. . Retrieved 2007-06-09. 7 Oppel, Andy (March 1, 2004). Databases Demystified (http://www.mhprofessional.com/product.php?cat=112&isbn=0072253649). San Francisco, CA: McGraw-Hill Osborne Media. pp. 90–91. ISBN 0-07-225364-9. . 8 "History of IBM, 1978" (http://www-03.ibm.com/ibm/history/history/year_1978.html). IBM Archives. IBM. . Retrieved 2007-06-09. SQL 11 9 ANSI/ISO/IEC International Standard (IS). Database Language SQL—Part 2: Foundation (SQL/Foundation). 1999. 10 "INTO Clause (Transact-SQL)" (http://msdn2.microsoft.com/en-us/library/ms188029(SQL.90).aspx). SQL Server 2005 Books Online. Microsoft. 2007. . Retrieved 2007-06-17;. 11 ISO/IEC (2003). ISO/IEC 9075-1:2003, "SQL/Framework" (http://www.iso.org). ISO/IEC. Section 4.4.2: The null value. . 12 Coles, Michael (2005-06-27). "Four Rules for Nulls" (http://www.sqlservercentral.com/columnists/mcoles/fourrulesfornulls.asp). SQL Server Central (Red Gate Software). . 13 ISO/IEC. ISO/IEC 9075-2:2003, "SQL/Foundation". ISO/IEC. 14 M. Negri, G. Pelagatti, L. Sbattella (1989) Semantics and problems of universal quantification in SQL (http://portal.acm.org/citation. cfm?id=63224.68822&coll=GUIDE&dl=GUIDE). 15 Fratarcangeli, Claudio (1991). Technique for universal quantification in SQL. Retrieved from ACM.org. (http://portal.acm.org/citation. cfm?id=126482.126484&coll=GUIDE&dl=GUIDE&CFID=5934371&CFTOKEN=55309005) 16 Kawash, Jalal (2004). Complex quantification in Structured Query Language (SQL): a tutorial using relational calculus - Journal of Computers in Mathematics and Science Teaching ISSN 0731-9258 Volume 23, Issue 2, 2004 AACE Norfolk, Virginia. Retrieved from Thefreelibrary.com (http://www.thefreelibrary.com/Complex+quantification+in+Structured+Query+Language+(SQL):+a+tutorial... -a0119901477). 17 Information Technology - Database Language SQL (Proposed revised text of DIS 9075) (http://www.contrib.andrew.cmu.edu/shadow/ sql/sql1992.txt). 18 Arie Jones, Ryan K. Stephens, Ronald R. Plew, Alex Kriegel, Robert F. Garrett (2005), SQL Functions Programmer's Reference. Wiley, 127 pages. 19 American National Standards Institute. X3H2 Records, 1978-1995. Finding Aid. (http://special.lib.umn.edu/findaid/xml/cbi00168.xml) 20 Melton, Jim; Alan R Simon (1993). Understanding the New SQL: A Complete Guide. Morgan Kaufmann. p. 536. ISBN 1558602453. "chapter 1.2 What is SQL? SQL (correctly pronounced "ess cue ell," instead of the somewhat common "sequel"), is a..." 21 Doll, Shelley (June 19, 2002). "Is SQL a Standard Anymore?" (http://articles.techrepublic.com.com/5100-10878_11-1046268.html). TechRepublic's Builder.com. TechRepublic. . Retrieved 2010-01-07. 22 Sybase.com (http://iablog.sybase.com/paulley/2008/07/sql2008-now-an-approved-iso-international-standard/). 23 Zip archive of the SQL:2008 draft (http://www.wiscorp.com/sql200n.zip) from Whitemarsh Information Systems Corporation. 24 ISO/IEC 9075-11:2008: Information and Definition Schemas (SQL/Schemata). 2008. p. 1. • "A Relational Model of Data for Large Shared Data Banks" (http://www.acm.org/classics/nov95/toc.html) E. F. Codd, Communications of the ACM, Vol. 13, No. 6, June 1970, pp. 377–387. • Discussion on alleged SQL flaws (C2 wiki) External links • 1995 SQL Reunion: People, Projects, and Politics, by Paul McJones (ed.) (http://www.mcjones.org/System_R/ SQL_Reunion_95/sqlr95.html): transcript of a reunion meeting devoted to the personal history of relational databases and SQL. • American National Standards Institute. X3H2 Records, 1978-1995 (http://special.lib.umn.edu/findaid/xml/ cbi00168.xml) Charles Babbage Institute Collection documents the H2 committee’s development of the NDL and SQL standards. • Oral history interview with Donald D. Chamberlin (http://www.cbi.umn.edu/oh/display.phtml?id=317) Charles Babbage Institute In this oral history Chamberlin recounts his early life, his education at Harvey Mudd College and Stanford University, and his work on relational database technology. Chamberlin was a member of the System R research team and, with Raymond F. Boyce, developed the SQL database language. Chamberlin also briefly discusses his more recent research on XML query languages. • Comparison of Different SQL Implementations (http://troels.arvin.dk/db/rdbms/) This comparison of various SQL implementations is intended to serve as a guide to those interested in porting SQL code between various RDBMS products, and includes comparisons between SQL:2008, PostgreSQL, DB2, MS SQL Server, MySQL, Oracle, and Informix. SQL:2003 12 SQL:2003 SQL:2003 is the fifth revision of the SQL database query language. The latest revision of the standard is SQL:2008. Summary The SQL:2003 standard makes minor modifications to all parts of SQL:1999 (also known as SQL3), and officially 1 introduces a few new features such as: • XML-related features (SQL/XML) • Window functions • the sequence generator, which allows standardized sequences • two new column types: auto-generated values and identity-columns • the new MERGE statement • extensions to the CREATE TABLE statement, to allow "CREATE TABLE AS" and "CREATE TABLE LIKE" • removal of the poorly-implemented "BIT" and "BIT VARYING" data types Documentation availability 2 3 The SQL standard is not freely available. SQL:2003 may be purchased from ISO or ANSI . A late draft is 4 5 available as a zip archive from Whitemarsh Information Systems Corporation . The zip archive contains a number of PDF files that define the parts of the SQL:2003 specification. • ISO/IEC 9075(1-4,9-11,13,14):2003 CD-ROM (352 CHF, or approximately 225 EUR, to order the CD) 6 • ISO/IEC 9075-1:2003 – Framework (SQL/Framework) 7 • ISO/IEC 9075-2:2003 – Foundation (SQL/Foundation) 8 • ISO/IEC 9075-3:2003 – Call-Level Interface (SQL/CLI) 9 • ISO/IEC 9075-4:2003 – Persistent Stored Modules (SQL/PSM) 10 • ISO/IEC 9075-9:2003 – Management of External Data (SQL/MED) 11 • ISO/IEC 9075-10:2003 – Object Language Bindings (SQL/OLB) 12 • ISO/IEC 9075-11:2003 – Information and Definition Schemas (SQL/Schemata) 13 • ISO/IEC 9075-13:2003 – SQL Routines and Types Using the Java Programming Language (SQL/JRT) 14 • ISO/IEC 9075-14:2003 – XML-Related Specifications (SQL/XML) External links 15 • BNF Grammar for ISO/IEC 9075-1:2003 – SQL/Framework 16 • BNF Grammar for ISO/IEC 9075-2:2003 – SQL/Foundation References 1 Eisenberg, Andrew; et al. (March 2004). "SQL:2003 Has Been Published" (http://www.acm.org/sigmod/record/issues/0403/index. htmlstandards) (pdf). SIGMOD Record 33 (1): 119. doi:10.1145/974121.974142. . Retrieved 2007-08-14. 2 http://www.iso.org/ 3 http://webstore.ansi.org/ 4 http://www.wiscorp.com/sql_2003_standard.zip 5 http://www.wiscorp.com/ 6 http://www.iso.org/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=34132 7 http://www.iso.org/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=34133 8 http://www.iso.org/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=34134 9 http://www.iso.org/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=34135 10 http://www.iso.org/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=34136 SQL:2003 13 11 http://www.iso.org/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=34137 12 http://www.iso.org/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=34917 13 http://www.iso.org/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=37102 14 http://www.iso.org/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=35341 15 http://savage.net.au/SQL/sql-2003-1.bnf.html 16 http://savage.net.au/SQL/sql-2003-2.bnf.html SQL:2008 SQL:2008 is the sixth revision of the SQL database query language. Summary The SQL:2008 standard was published in 2008. Documentation availability The SQL standard is not freely available. The whole standard may be purchased from the ISO as ISO/IEC 9075(1-4,9-11,13,14):2008. The standard consists of the following parts: 1 • ISO/IEC 9075-1:2008 Framework (SQL/Framework) 2 • ISO/IEC 9075-2:2008 Foundation (SQL/Foundation) 3 • ISO/IEC 9075-3:2008 Call-Level Interface (SQL/CLI) 4 • ISO/IEC 9075-4:2008 Persistent Stored Modules (SQL/PSM) 5 • ISO/IEC 9075-9:2008 Management of External Data (SQL/MED) 6 • ISO/IEC 9075-10:2008 Object Language Bindings (SQL/OLB) 7 • ISO/IEC 9075-11:2008 Information and Definition Schemas (SQL/Schemata) 8 • ISO/IEC 9075-13:2008 SQL Routines and Types Using the Java TM Programming Language (SQL/JRT) 9 • ISO/IEC 9075-14:2008 XML-Related Specifications (SQL/XML) References 1 http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=45498 2 http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=38640 3 http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=38641 4 http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=38642 5 http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=38643 6 http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=38644 7 http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=38645 8 http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=38646 9 http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=45499 Advantage Database Server 14 Advantage Database Server Developer(s) Sybase Initial release Written in C, C++ Operating Cross-platform system Available in English Type RDBMS Website advantagedatabase.com 1 Advantage Database Server is a relational database management system (RDBMS) for small to medium sized businesses by Sybase iAnywhere. Database author Cary Jensen describes Advantage as follows: "Advantage has been around since 1993, when it was introduced to provide a stable solution for Clipper developers who were tired of slow performance and corrupt indexes inherent to file server-based databases. Over the years, ADS has grown in both popularity and features. Advantage is now a mature product with an impressive collection of features that rival 2 many of the more expensive and complicated database servers" . “In short, the Advantage Database Server is a high-performance, low-maintenance, remote database server that 3 permits you to easily build and deploy client/server applications and web-based applications” . Uses Advantage Database Server is most popular among application developers as a client/server backend solution for shared, networked, standalone, mobile and Internet database applications. ADS is unique among other database offerings because it provides both ISAM table-based and SQL based data access. Features • Replication • Online Backup • ISAM access • SQL-92 compliant • SQL Query Optimizer • User Defined Functions • Triggers • Stored Procedures • Views • Server Side Aliases • Encrypted indexes and communications • DBF tables and memos greater than 4 gigabytes • Transactions • Events / Notifications • 64-bit support • Full Text Search • Multiple Processor support Advantage Database Server 15 • Small footprint Programming Languages • Popular development environments including CodeGear Delphi, CodeGear C++Builder, Microsoft Visual Basic, Microsoft Visual C++, CA-Visual Objects, CA-Clipper and Microsoft Visual FoxPro. • Supports standard interfaces such as ODBC, OLE DB, JDBC, PHP, and ADO.NET. History • August 1993 – Initially released as Advantage xBase server by Extended Systems. • December 1995 – version 4.0 release, now called Advantage Database Server. This release included the first ODBC driver. • February 1997 – Advantage Internet Server released. • April 2000 – Advantage ODBC driver with StreamlineSQL released. 4 • November 2005 – Advantage Database Server: The Official Guide published . • November 2005 – Extended Systems acquired by Sybase, rolled in to iAnywhere Solutions subsidiary. • November 2008 – The latest version was released, Advantage Database Server 9.1. See also • Comparison of relational database management systems • Sybase iAnywhere External links 5 • Advantage Database Server website 6 • iAnywhere website on Sybase.com 7 • JD was here – Advantage blog 8 • Chris Franz's Advantage blog 9 • Cary Jensen’s website 10 • Advantage Developer Zone References 1 http://www.advantagedatabase.com/ 2 Cary Jensen, Ph.D.Loy Anderson, Ph.D, Advantage Database Server: A Developer's Guide, February 5, 2007, 616 pages, AuthorHouse, 978-1425-7726-9 3 Cary Jensen, Ph.D.Loy Anderson, Ph.D, Advantage Database Server: A Developer's Guide, February 5, 2007, page 7, AuthorHouse, 978-1425-7726-9 4 Cary Jensen, Ph.D.Loy Anderson, Ph.D, Advantage Database Server: The Official Guide, October 29, 2003, 496 pages, McGraw-Hill Osborne Media, 0-07-223084-1 5 http://www.sybase.com/products/databasemanagement/advantagedatabaseserver/ 6 http://www.sybase.com/iAnyhwhere 7 http://jdmullin.blogspot.com/ 8 http://blog.advantageevangelist.com/ 9 http://www.jensendatasystems.com/ 10 http://devzone.advantagedatabase.com/ Apatar 16 Apatar Stable release v1.0.8.6 / September 21, 2007 Operating Cross-platform system Type ETL, Data migration and SQL. License General Public License version 2.0 1 Website apatarforge.org Apatar is an open source ETL (Extract-Transform-Load) and mashup data integration software application. Other open source data integration projects are Clover.ETL, Pentaho Project, Talend Open Studio or Enhydra Octopus. Typical use • Database migration. • Application integration • Database creation/update scripts. • Cross-database operations, import/export. • Automated database schema upgrade. 2 Apatar open source project was founded in 2005 . Apatar, Inc., a commercial company providing support for 3 Apatar open source software, was founded in 2007 . Users of Apatar software include R.R. Donnelley and 4 5 6 Autodesk , . Apatar data integration software is adopted for Amazon Web Services platform . External links 7 • Apatar Website 8 • Apatar project page on SourceForge.Net 1 • Apatar Community Website References 1 http://www.apatarforge.org 2 "Apatar Crashes Data Mashup Party" (http://www.sdtimes.com/article/story-20070715-13.html). SD Times (http://www.sdtimes.com). . Retrieved 2007-09-24. 3 "Open Source Companies to Watch" (http://www.networkworld.com/news/2007/082307-open-source-to-watch.html). NetworkWorld (http://www.networkworld.com). . Retrieved 2007-09-24. 4 "Two Ways To Deal With SOA's Data Integration Challenge" (http://www.informationweek.com/software/showArticle. jhtml?articleID=200900682&pgno=2&queryText=). InformationWeek (http://www.informationweek.com). . Retrieved 2007-09-24. 5 "Young software exec moves to open source model" (http://masshightech.bizjournals.com/masshightech/stories/2007/07/16/story12. html?page=2). American City Business Journals, Inc. (http://bizjournals.com). . Retrieved 2007-09-24. 6 "Open Source Companies to watch" (http://www.informationweek.com/news/showArticle.jhtml?articleID=201300517). InformationWeek (http://www.informationweek.com). . Retrieved 2007-09-24. 7 http://www.apatar.com 8 http://sourceforge.net/projects/apatar Call Level Interface 17 Call Level Interface The Call Level Interface (CLI) is a software standard defined in ISO/IEC 9075-3:2003. The Call Level Interface defines how a program should send SQL queries to the database management system (DBMS) and how the returned recordsets should be handled by the application in a consistent way. Developed in the early 1990s, the API was defined only for the C and COBOL programming languages. The interface is part of what The Open Group refers to as the Common Application Environment, which is intended to be a wide standard for programming open applications, i.e. applications from different programming teams and different vendors that can interoperate in an efficient manner. SQL/CLI provides an international standard implementation-independent CLI to access SQL databases. Client-server tools can easily access databases through Dynamic-link libraries (DLL). It supports and encourages a rich set of client-server tools. The most widespread use of the CLI standard is the basis of the ODBC (Open Database Connectivity) specification, which is widely used to allow applications to transparently access database systems from different vendors. The current version of the API, ODBC 3.52, incorporates features from both the ISO and X/Open standards (see below). History The work with the Call Level Interface began in a subcommittee of the US-based SQL Access Group. In 1992, it was initially published and marketed as Microsoft's ODBC API. The CLI specification was submitted as to the ISO and ANSI standards committees in 1993; the standard has the book number ISBN 1-85912-081-4 and the internal document number is C451. ISO SQL/CLI is an addendum to 1992 SQL standard (SQL-92). It was completed as ISO standard ISO/IEC 9075-3:1995 Information technology Database languages SQL Part 3: Call-Level Interface (SQL/CLI). The current SQL/CLI effort is adding support for SQL3. In the fourth quarter of 1994, control over the standard was transferred to the X/Open Company, which significantly expanded and updated it. The X/Open CLI interface is a superset of the ISO SQL CLI. This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL. External links 1 • Online definition of CLI at The Open Group webpage References 1 http://www.opengroup.org/products/publications/catalog/c451.htm Cardinality (SQL statements) 18 Cardinality (SQL statements) In SQL (Structured Query Language), the term cardinality refers to the uniqueness of data values contained in a particular column (attribute) of a database table. The lower the cardinality, the more duplicated elements in a column. Thus, a column with the lowest possible cardinality would have the same value for every row. SQL databases use cardinality to help determine the optimal query plan for a given query. Values of Cardinality When dealing with columnar value sets, there are 3 types of cardinality: high-cardinality, normal-cardinality, and low-cardinality. High-cardinality refers to columns with values that are very uncommon or unique. High-cardinality column values are typically identification numbers, email addresses, or user names. An example of a data table column with high-cardinality would be a USERS table with a column named USER_ID. This column would contain unique values of 1-n. Each time a new user is created in the USERS table, a new number would be created in the USER_ID column to identify them uniquely. Since the values held in the USER_ID column are unique, this column's cardinality type would be referred to as high-cardinality. Normal-cardinality refers to columns with values that are somewhat uncommon. Normal-cardinality column values are typically names, street addresses, or vehicle types. An example of a data table column with normal-cardinality would be a CUSTOMER table with a column named LAST_NAME, containing the last names of customers. While some people have common last names, such as Smith, others have uncommon last names. Therefore, an examination of all of the values held in the LAST_NAME column would show "clumps" of names in some places (e.g.: a lot of Smith's ) surrounded on both sides by a long series of unique values. Since there is a variety of possible values held in this column, its cardinality type would be referred to as normal-cardinality. Low-cardinality refers to columns with few unique values. Low-cardinality column values are typically status flags, boolean values, or major classifications such as gender. An example of a data table column with low-cardinality would be a CUSTOMER table with a column named NEW_CUSTOMER. This column would contain only 2 distinct values: Y or N, denoting whether the customer was new or not. Since there are only 2 possible values held in this column, its cardinality type would be referred to as low-cardinality. See also • Cardinality (mathematics) Check Constraint 19 Check Constraint A check constraint (also known as table check constraint) is a condition that defines valid data when adding or updating an entry in a table of a relational database. A check constraint is applied to each row in the table. The constraint must be a predicate. It can refer to a single or multiple columns of the table. The result of the predicate can be either TRUE, FALSE, or UNKNOWN, depending on the presence of NULLs. If the predicate evaluates to UNKNOWN, then the constraint is not violated and the row can be inserted or updated in the table. This is contrary to predicates in WHERE clauses in SELECT or UPDATE statements. For example, in a table containing products, one could add a check constraint such that the price of a product and quantity of a product is a non-negative value: PRICE = 0 QUANTITY = 0 If these constraints were not in place, it would be possible to have a negative price (-30) or quantity (-3 items). Check constraints are used to ensure the validity of data in a database and to provide data integrity. If they are used at the database level, applications that use the database will not be able to add invalid data or modify valid data so the data becomes invalid, even if the application itself accepts invalid data. Definition Each check constraint has to be defined in the CREATE TABLE or ALTER TABLE statement using the syntax: CREATE TABLE table_name ( ..., CONSTRAINT constraint_name CHECK ( predicate ), ... ) ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK ( predicate ) If the check constraint refers to a single column only, it is possible to specify the constraint as part of the column definition. CREATE TABLE table_name ( ... column_name type CHECK ( predicate ), ... )

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.