1 SQL: Structured Query Language The Relational Database Standard The name SQL is derived from Structured Query Language. Originally, SQL was called SEQUEL (for Structured English Query Language) and was designed and implemented at IBM Research for a database system called System R. A joint effort between ANSI and ISO has led to standard version of SQL, called SQL 86 or SQL1. This version was expanded to a new standard SQL2. SQL is a comprehensive database language; it has statement for data definition, query and update. Hence, it is both a DDL and DML. In addition, it has facilities for defining views on the database for specifying security and authorization, for defining integrity constraints, and for specifying transaction control. It also has rules for embedding SQL statements into general purpose programming languages. Data Definition, Constraints and Schema Changes in SQL: SQL uses the terms table, row and column for relation, tuple, and attribute, respectively. The SQL commands for data definition are CREATE, ALTER and DROP. Schema and Catalog Concepts in SQL: The concept of an SQL schema was introduced in order to group together tables and other constructs that belong to the same database application. An SQL schema is identified by a schema name, and includes an authorization identifier to indicate the user or account who owns the schema, as well as descriptors for each element in the schema. Schema elements include the tables, constraints, views, domains and others. A schema is created via the CREATE SCHEMA statement, which can include all the schema elements definitions. Alternatively, the schema can be defined by giving it a name and an authorization and its elements can be defined later on. CREATE SCHEMA COMPANY AUTHORIZATION Jsmith
2 This statement creates a schema called company, owned by the user with authorization identifier Jsmith. SQL also uses the concept of catalog a named collection of schemas in an SQL environment. A catalog always contains a special schema called INFORMATION_SCHEMA, which provides information on all the element descriptors of all the schemas in the catalog to authorized users. Integrity constraints such as referential integrity can be defined between relations only if they exist in the same catalog. Schemas within the same catalog can also share elements, such as domain definitions. The CREATE TABLE Command in SQL: The CREATE TABLE command is used to specify a new relation by giving it a name and specifying attributes and initial constraints. The general format: CREATE TABLE newtablename( ); Three part attribute description, Three part attribute description, Optional table constraints... The attributes are specified first and each attribute is given a name, a data type to specify its domain of values and any attribute constraints such as NOT NULL. The
3 key, entity integrity and referential integrity constraints can be specified after the attributes are declared. Or they can be added later using ALTER TABLE command. The SQL schema in which the relations are declared is implicitly specified in the environment in which the CREATE TABLE statements are executed. It can explicitly be specified by attaching the schema name to the relation names using the dot (.) operator. CREATE TABLE COMPANY.EMPLOYEE rather than CREATE TABLE EMPLOYEE The relations declared through CREATE TABLE statement are called base tables (or base relations). These are actually created and stored as a file by the DBMS. Base relations are distinguished from virtual relations created through the CREATE VIEW statement, which may or may not correspond to an actual physical file. In SQL, the attributes in a base table are considered to be ordered in the sequence in which they are specified, in the CREATE TABLE statement. Attributes Data Types and Domains in SQL: The basic data types available: Numeric data types include: integer numbers : INTEGER, INT or SMALLINT. Floating point: real numbers : FLOAT or REAL, DOUBLE PRECISION. Formatted numbers can be declared using DECIMAL(i,j) or DEC(i,j) or NUMERIC(i, j) where I is the total number of decimal digits and j, the number of digits after the decimal point. Character string: Data types are either fixed length or varying length strings. CHAR(n) or CHARACTER(n) where n is the number of characters. VARCHAR(n), CHAR VARYING (n) or CHARACTER VARYING(n), where n is the maximum number of characters. When specifying a literal string value, it should be placed between single quotes. Strings are case sensitive. In case the data item is shorter than the allocated size, it is padded with blank
4 spaces. For comparison purposes, strings are considered ordered in lexicographic order. Concatenation operator, denoted that can concatenate two strings in SQL. CHARACTER LARGE OBJECT or CLOB is used to specify the data type of columns that have large text values, such as documents. The CLOB maximum length can be specified in Kilobytes (K), Megabytes(M) or Gigabytes (G), example CLOB(20M) Bit string data types are bit arrays that compactly stores bits or BOOLEAN values. Fixed length n declared as BIT(n) or varying length BIT VARYING(n) where n is the maximum number of bits. The default for n is 1. Literal bit strings are placed between single quotes and preceded by B, example B BINARY LARGE OBJECT or BLOB is available to specify columns that have large binary values, such as images. The BLOB maximum length can be specified in Kilobytes (K), Megabytes(M) or Gigabytes (G), example BLOB(20M) Boolean data type : Have the traditional TRUE, FALSE values. In SQL because of the presence of NULL values, a three valued logic is used (TRUE, FALSE and UNDETERMINED) The DATE data type has 10 positions and its components are YEAR, MONTH and DAY in the form YYYY MM DD. The TIME data type has at least eight positions with the components HOUR, MINUTE and SECOND in the form HH:MM:SS. SQL checks for valid dates and times and there is a check between the month number and its allowed number of days as well. Time values are represented like literal strings between single quotes preceded by the keywords DATE or TIME. Example: DATE or TIME 11:12:12
5 The timestamp data type(timestamp) includes the DATE and TIME fields and other items. Example :, TIMESTAMP :23: User defined Data types: SQL allows users to specify the data type directly using the CREATE DOMAIN statement. This makes it easier to change the schema and also improves the schema readability. CREATE DOMAIN SSN_TYPE AS CHAR(9); We can use SSN_TYPE in place of CHAR(9) for the relevant attributes in our database relations. Specifying constrains and default values in SQL: Constraints on Attribute Values: Since SQL allows NULL for attribute values, a constraint NOT NULL may be specified if NULL is not allowed for a particular attribute. This constraint should always be specified for the primary key attributes of each relation. For example: Dnumber INT NOT NULL CHECK (Dnumber > 0 AND Dnumber <21) An attribute can be assigned a default value by appending the clause DEFAULT<value> to an attribute definition. The default value is included in any new tuple if an explicit value is not provided for the attribute. If no default clause is specified, the default default value(!) is NULL. Dno INT NOT NULL DEFAULT 1, The CHECK clause can also be used in conjunction with CREATE DOMAIN statement. For example:
6 CREATE DOMAIN D_NUM AS INTEGER CHECK (D_NUM >0 AND D_NUM< 21) We can then use the created domain D_NUM as the attribute data type for all attributes that refer to department numbers. Dno D_NUM DEFAULT 1, Specifying Key and Referential Integrity Constraints: Because keys and referential integrity constraints are very important, there are special clauses within the CREATE TABLE statement to specify them. These are table constraints The PRIMARY KEY clause specifies that one or more attributes make up the primary key of the relation. If a primary key has a single attribute, the clause can follow the attribute directly. For example: DNumber INT PRIMARY KEY; The UNIQUE clause specifies alternate (secondary) keys. Dname VARCHAR(15) UNIQUE; Table constraints A table constraint, identified by the word CONSTRAINT A constraint is defined as: CONSTRAINT constrainname Constraint clause, CONSTRAINT is a reserved word, constraintname is an identifier that uniquely identify the constraint. Constraint Clauses: Additional table constraints can be specified in a table, including keys and referential integrity. Keys constraints are specified in a PRIMARY KEY constraint and/or UNIQUE constraint. The UNIQUE clause specifies alternate (or secondary) keys.
7 The PRIMARY KEY clause specified one or more attributes that make up the primary key of a relation. Referential constraints: Referential integrity is specified via the FOREIGN KEY clause. Referential integrity is specified via the FOREIGN KEY clause. CREATE TABLE EMPLOYEE (..., Dno INT NOT NULL DEFAULT 1, CONSTRAINT EMPPK PRIMARY KEY (SSN), CONSTRAINT EMPSUPERFK FOREIGN KEY(SUPERSSN) REFERENCES EMPLOYEE(SSN) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT EMPDETFK FOREIGN KEY (Dno) REFERENCES DEPARTMENT(DNUMBER) ON DELETE SET DEFAULT ON UPDATE CASCADE ); CREATE TABLE DEPART_LOCATIONS (..., PRIMARY KEY (Dnumber, Dlocation), FOREIGN KEY(SUPERSSN) REFERENCES EMPLOYEE(SSN) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT EMPDETFK FOREIGN KEY (Dnumber) REFERENCES DEPARTMENT(Dnumber) ON DELETE CASCADE ON UPDATE CASCADE );
8 Referential Trigger Actions: A referential integrity constraint can be violated when tuples are inserted or deleted or when a foreign key attribute value is modified. It is then necessary to specify the actions to be taken if such a constraint is violated upon deletion of a referenced tuple or upon modification of a referenced primary key value by attaching a referential trigger action clause to any foreign key value. The options for triggered action clauses are SET NULL, CASCADE and SET DEFAULT. The action taken by the DBMS for SET NULL or SET DEFAULT is the same for both ON DELETE and ON UPDATE, the value of the affected referencing attributes is changed to NULL for SET NULL or to the specified default value for SET DEFAULT. The action for CASCADE ON DELETE is to delete all the referencing tuples, whereas the action for CASCADE ON UPDATE is to change the value of the foreign key to the new primary key value for all referencing tuples. CREATE TABLE DEPARTMENT (..., MGRSSN CHAR(9) NOT NULL DEFAULT ,, CONSTRAINT DEPTPK PRIMARY KEY (DNUMBER), CONSTRAINT DEPTSK UNIQUE (DNAME), CONSTRAINT DEPTMGRFK FOREIGN KEY (MGRSSN) REFERENCES EMPLOYEE(SSN) ON DELETE SET DEFAULT ON UPDATE CASCADE );
9 The DROP SCHEMA and DROP TABLE Commands: If a whole database schema is no longer needed, the DROP SCHEMA command can be used to delete the database. There are two DROP options: CASCADE and RESTRICT DROP SCHEMA COMPANY CASCADE Causes the database schema to be removed and all its tables. DROP SCHEMA COMPANY RESTRICT Causes the schema to be dropped only if there are no elements in it; otherwise the DROP command will not be executed. In order to delete a base relation within a schema and its definition, we use the DROP TABLE clause. To remove all dependent relation by entering the command: DROP TABLE DEPENDENT CASCADE. If the RESTRICT option is used, a relation(table) is deleted only if it is not referenced in any constraints. With the CASCADE option, all such constraints and views that reference the table are dropped from the schema along with the table itself. The ALTER TABLE Command: The definition of a base table can be changed by using the ALTER TABLE command, which is a schema evolution command. Possible modifications include adding or dropping an attribute, changing an attribute definition, and adding or dropping table constraints. ALTER TABLE COMPANY.EMPLOYEE ADD JOB VARCHAR(12); Adds an attribute JOB for each individual EMPLOYEE tuple. ALTER TABLE COMPANY.EMPLOYEE DROP ADDRESS CASCADE; ( to drop an attribute)
10 ALTER TABLE COMPANY.DEPARTMENT ALTER MGRSSN DROP DEFAULT; (drop default value for the MGRSSN attribute) ALTER TABLE COMPANY.DEPARTMENT ALTER MGRSSN SET DEFAULT ; (changes default value to MGRSSN attribute). Specifying Key and Constraints can also be dropped or changed on a table. A constraint must have been given a name when it is specified. A constraint is dropped by using the statement: DROP CONSTRAINT ConstraintName CASCADE; ADD CONSTRAINT ConstrainName ALTER TABLE COMPANY.EMPLOYEE DROP CONSTRAINT EMPSUPERFK CASCADE; ADD CONSTRAINT NEWCONSTRAINT Basic Queries in SQL: The SELECT statement: SELECT is the basic statement to retrieve information from a database. SQL allows a table (relation) to have two or more tuples identical in all their attribute values, consequently an SQL table is not a set of tuples, it is rather a bag of tuples. Some SQL relations are constrained to be sets because of key constraint has been declared. The SELECT FROM WHERE Structure of SQL Queries: The basic form of the SELECT statement, sometimes called a mapping is formed of the three clauses SELECT, FROM, and WHERE :
11 Where: SELECT <attribute list> FROM <table list> WHERE <condition> <attribute list> is a list of attribute names whose values are to be retrieved by the query <table list> is a list of relation names <condition> is a conditional expression that identifies the tuples to be retrieved by the query. A more general version is: SELECT <attribute list> FROM <table list> [ WHERE <condition>] [ORDER BY < attribute list>] with the clauses between  being optional. Q0: Retrieve the bithdate and address of the employee(s) whose name is John B. Smith SELECT BDATE, ADDRESS FROM EMPLOYEE WHERE FNAME= John AND MINIT= B AND LNAME= Smith ; QUERY 1: Retrieve the name and address of all employees who work for the Research department.
12 Q1: SELECT FNAME, LNAME, ADDRESS FROM EMPLOYEE, DEPARTMENT WHERE DNAME= Research AND DNUMBER=DNO QUERY 2: For every project located in Stafford, list the project number, the controlling department number, and the department manager s last name, address, and birthdate. Q2: SELECT PNUMBER, DNUM, LNAME, ADDRESS, BDATE FROM PROJECT, DEPARTMENT, EMPLOYEE WHERE PLOCATION= Stafford AND DNUM=DNUMBER AND MGRSSN=SSN; Dealing with Ambiguous Attribute Names and Renaming: In SQL, the same name can be used for two (or more) attributes as long as the attributes are in different relations. If a query refers to two or more attributes with the same name, we must qualify the attribute name with the relation name and separate them with a dot(.). This is done by prefixing the relation name to the attribute name. Ambiguity also arises in the case of queries that refer to the same relation twice as in the following QUERY: For each employee, retrieve the employee s first and last name and the first and last name of his or her immediate supervisor. Q8: SELECT E.FNAME, E.LNAME, S.FNAME, S.LNAME FROM EMPLOYEE AS E, EMPLOYEE AS S WHERE E.SUPERSSN=S.SSN In this case, we declare tuple variable or aliases, for the EMPLOYEE relation.
13 An alias can follow the keyword AS or it can directly follow the relation name as in : FROM EMPLOYEE E, EMPLOYEE S It is also possible to rename the relation attributes within the query in SQL by giving them aliases; for example: EMPLOYEE AS E (FN,MI, LN, SSN,BD,ADDR,SEX,SAL,SSSN,DNO) Unspecified WHERE Clause and Use of * A missing WHERE clause indicates that no condition on tuple selection. Hence this type of SELECT will retrieve all tuple of the relations specified in the FROM qualify and are selected for the query result. QUERIES 9 and 10: Select all employees ssns SELECT FROM SSN EMPLOYEE; Select all combinations of EMPLOYEE SSN and DEPARTMENT DNAME in the database. SELECT FROM SSN, DNAME EMPLOYEE, DEPARTMENT; It is very important to specify every selection in the WHERE clause. If such conditions are overlooked, incorrect or very large relations maybe result. To retrieve all attributes values of selected tuples, we do not need to list each attribute name explicitly in SQL; we can just enter (*) which stands for all attribute.
14 QUERY: Retrieve all attributes of an EMPLOYEE and the attributes of the DEPARTMENT he/she works in for every employee of the Research department. SELECT * FROM EMPLOYEE WHERE DNO =5; SELECT * FROM EMPLOYEE, DEPARTMENT WHERE DNAME= Research AND DNO=DNUMBER; Tables as Sets in SQL: SQL does not automatically eliminate duplicate tuples in the results of queries: They are expensive. the user may want to see duplicate tuples An SQL table with a key is however a set with no duplicate tuples. If we want to eliminate duplicate tuples from the result of an SQL query, we use the keyword DISTINCT in the SELECT clause, so as to eliminate all duplicate tuples. SELECT ALL and SELECT are equivalent in that they do not eliminate duplicate tuples. SELECT ALL Salary
15 FROM EMPLOYEE; SELECT DISTINCT Salary FROM EMPLOYEE; SET Operations: SQL has incorporated some Set building operations as defined in mathematics, such as set union: UNION and set intersection (INTERSECT) and set difference (EXCEPT). The relations resulting from these set operations are sets of tuples, in which duplicates are eliminated from the results. (SELECT DISTINCT Pnumber FROM PROJECT, DEPARTMENT, EMPLOYEE WHERE Dnum= Dnumber AND Mgr_ssn= Ssn AND Lname= Smith ); UNION (SELECT DISTINCT Pnumber FROM WHERE PROJECT, WORKS_ON, EMPLOYEE Pnumber= Pno AND Essn= Ssn AND Lname= Smith ); The first SELECT query retrieves the projects that involve Smith as a manager of the department that controls the project. The second SELECT query retrieves the projects that involve Smith as worker on the project.
16 SQL also has corresponding multiset operations which use the set operator followed by the keyword ALL (UNION ALL, INTERSECT ALL, EXCEPT ALL). Their results are bags in that duplicates are not eliminated. Substring Pattern Matching and arithmetic Operators: String pattern matching: The LIKE operator is used for comparing strings values in tuples and for string pattern matching. Partial strings are specified using two reserved characters % replaces an arbitrary number (0 or more) of characters, whereas _ replaces a single character. SELECT Fname, Lname FROM EMPLOYEE WHERE Address LIKE %Houston, TX% Retrieves all employees whose address is in Houston, Texas SELECT Fname, Lname FROM EMPLOYEE WHERE BDate LIKE 5 Retrieves all employees born in the 1950 s Note: if the underscore or % is part of the string, it should be preceded by the keyword ESCAPE. For example AB\_CD\%F ESCAPE \ represents the string AB_CD%F and \ is specified as the escape character. Any character not used in the string, can be chosen as the escape character. If the single quote symbol or apostrophe is part of the string, then they are entered as so it will not be interpreted as the string ending symbol.
17 Substring comparison implies that the attribute values are strings. Arithmetic operators in queries: The standard arithmetic operators +. *, and / can be applied to numeric values or attributes with numeric domains. For example: suppose we want to see the effect of giving a 10% raise to all employees working on ProductX, we can issue the query: SELECT E.Fname, E.Lname, 1.1*E.Salary AS Increased_sal FROM EMPLOYEE AS E, WORKS_ON AS W, PROJECT AS P WHERE E.Ssn=W.Essn AND W.Po= P.Pnumber AND P.Pname= ProductX ; For string data types, the concatenate operator can be used to append two string values. For date, time and interval data types, operators include incrementing (+) decrementing ( ) a date, a time or timestamp by an interval. BETWEEN: is a comparison operator that is used to check or retrieve tuples whose attribute value is between two values: SELECT * FROM EMPLOYEE WHERE (Salary BETWEEN AND 40000) AND Dno=5; (Salary BETWEEN AND 40000) is equivalent to (Salary <= 40000) AND (Salary >= 30000) Ordering of Query Results:
18 ORDER BY clause allows the user to order the result of the query by the values of one or more attributes. SELECT D.Dname, E.Lname, E.Fname, P.Pname FROM DEPARTMENT AS D, EMPLOYEE AS E, WORKS_ON AS W, PROJECT AS P WHERE D.Dnumber= E.Dno AND E.Ssn=W.Essn AND W.Po= P.Pnumber ORDER BY D.Dname, E.Lname, E.Fname; The default order is the ascending order of values. We can specify the order using either DESC for descending or ASC for ascending. ORDER BY D.Dname DESC, E.Lname ASC, E.Fname ASC; INSERT, DELETE and UPDATE statements in SQL: Three commands are used to modify the database: INSERT, DELETE, and UPDATE. The INSERT command: INSERT is used to add a single tuple to a relation. We must specify the relation name and the list of values for the tuple. The values should be listed in the same order in which their corresponding attributes were specified in the CREATE TABLE command. INSERT VALUES INTO EMPLOYEE ( Richard, K, Marini, , , 90 Oak Forest, Katy, TX, M, 37000, ,4); A second form of the INSERT statement allows the user to specify explicit attributes names that correspond to the values provided in the INSERT command.
19 This is useful if a relation has many attributes, but only a few of those are assigned values in the new tuple. However, the values must include ALL the attributes with NOT NULL specification and no default value. Attributes with NULL allowed or DEFAULT values are the ones that can be left out. INSERT INTO EMPLOYEE (Fname, Lname, Dno, Ssn) VALUES ( Richard, Marini, 4, ); Attributes not specified above are set to their DEFAULT or NULL values. Also, the tuple values should be listed in the same order as described in the INSERT line. Inserting multiple tuples: It is possible to insert multiple tuples in a single INSERT command by separating each tuple with a comma. The attribute values representing a tuple are put between parentheses. A DBMS that fully implements SQL should support and enforce all the integrity constraints that are specified in the DDL. QUERY INSERT: A variation of the INSERT command inserts multiple tuple into a relation in conjunction with creating a relation and loading it with the results of a query. For example, we want to create a temporary table that has the employee last name, project name and hours per week for each employee working on a project:
20 CREATE TABLE WORKS_ON_INFO (Emp_Name Proj_Name VARCHAR(15), VARCHAR(15), Hours_per_week Decimal (3, 1) ); INSERT INTO WORKS_ON_INFO (Emp_Name, Proj_Name, Hours_per_week) SELECT FROM WHERE E.Lname, P.Pname, W.Hours PROJECT P, EMPLOYEE E, WORKS_ON W P.Pnumber= W.Pno AND W.Essn= E.Ssn; A table WORKS_ON_INFO is created and is loaded with the joined information retrieved from the database by the query above. We can now query WORKS_ON_INFO as we would for any other table. When it is no longer needed, we can remove it using the DROP TABLE command. The DELETE command: The DELETE command removes tuples from a relation. It includes a WHERE clause to select the tuples to be deleted. Tuples are explicitly deleted from only one table at a time. However, the deletion may propagate to other tuples in other relations if referential triggered actions are specified in the referential integrity constraints of the DDL. Depending on the number of tuples selected by the WHERE clause, 0, 1 or more tuples can be deleted by a single DELETE command. A missing WHERE clause will cause all tuples in the table to be deleted. However, the empty table will remain in the database. The DROP TABLE command must be used to delete the table.
21 DELETE FROM EMPLOYEE WHERE Lname= Brown ; DELETE FROM EMPLOYEE WHERE Ssn= ; DELETE FROM EMPLOYEE WHERE Dno= 5; DELETE FROM EMPLOYEE; The UPDATE command: The UPDATE command is used to modify attribute values of one or more selected tuples. The WHERE clause in the update command selects the tuples to be modified from a single relation. An additional SET clause in the UPDATE command specifies the attributes to be modified and their new values. UPDATE PROJECT SET Plocation= Bellaire, Dnum=5 WHERE Pnumber= 10; Several tuples can be modified with a single UPDATE command. UPDATE EMPLOYEE SET Salary= Salary*1.1 WHERE Dno= 5; SQL in a nutshell: Comments: Comments start with and are terminated with the end of line or if there are multiple lines, we use the pairs /*.. */.
22 Names: Database items such as databases, tables, and columns are names using identifiers. An identifier is a sequence of letters and digits that have a maximum length of 128 characters and must begin with a letter. Names are case sensitive. Types: A datatype must be associated with every value stored in the databases. Datatypes are associated with attributes and all values in a column must be of the same datatype. Datatype Comment BOOLEAN True or false or unkown CHAR Single character VARCHAR(n) Variable length string with maximum size =n BLOB Large binary objects, such as images TEXT Same as VARCHAR strings with a very large max size INTEGER (INT) Normal size integer (2 bytes) SMALLINT Small Integer (1 byte) BIGINT Large integer (4 bytes) DECIMAL(precision, scale) Decimal number: precision is the display width and scale is the number of fractional digits (2 for currency) FLOAT Floating point number DOUBLE (REAL) Double precision floating point number DATE Date in YYYY MM DD format TIME Time in HH:MM:SS format DATETIME Time in YYYY MM DD HH:MM:SS format STRINGS: Strings are character sequences enclosed between pairs of single quotes. Special characters that can be used within strings: Special Character Meaning when used in a string \ Single quote character \ Double quote character
23 \b Backspace \n New line \r Carriage return \t Tab \\ Backslash % Without a preceding backslash, the percent is interpreted by the string operator LIKE as a wildcard matching 0 or more characters _ Without a preceding backslash, the underscore character is interpreted by the string operator LIKE as a wildcard matching a single character. Operators: Arithmetic: The usual arithmetic operators such as +., *, and / are available. LOGICAL: The logical operators return the value TRUE or FALSE, they are: NOT (or!) AND (or &&) OR (or ) XOR COMPARISON = (equal) >=(greater than or equal) > (greater than) <=( less than or equal) < (less than) <> ( not equal or!=) IS ( NULL test) BETWEEN (value is in a specified range) The IS operator can be used to test whether a value is NULL or NOT NULL as in: expression IS NULL (IS NOT NULL)
24 The BETWEEN operator is used to determine whether or not a value is within a specified range (including the end points) BETWEEN low AND high STRING: The string operators LIKE and NOT LIKE are used for string pattern matching: String LIKE pattern_string String NOT LIKE pattern_string PRECEDENCE: The precedence of the commonly used operators is: OR, XOR AND BETWEEN =, >=, >, <=, <, <>,!=, IS, LIKE, NOT LIKE,+ *, / (unary minus) FUNCTIONS: CEIL (rounds up to the nearest integer), and SIN (sine function, argument in radians)
Summary on Chapter 4 Basic SQL SQL Features Basic SQL DDL o Includes the CREATE statements o Has a comprehensive set of SQL data types o Can specify key, referential integrity, and other constraints Basic
CSC 443 Data Base Management Systems Lecture 6 SQL As A Data Definition Language Basic SQL SQL language Considered one of the major reasons for the commercial success of relational databases SQL Structured
Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations) of a database
8 SQL-99: Schema Definition, Basic Constraints, and Queries The SQL language may be considered one of the major reasons for the success of relational databases in the commercial world. Because it became
Introduction to SQL: Data Retrieving Ruslan Fomkin Databasdesign för Ingenjörer 1056F Structured Query Language (SQL) History: SEQUEL (Structured English QUery Language), earlier 70 s, IBM Research SQL
Part 4: Database Language - SQL Junping Sun Database Systems 4-1 Database Languages and Implementation Data Model Data Model = Data Schema + Database Operations + Constraints Database Languages such as
The Relational Algebra The relational algebra is very important for several reasons: 1. it provides a formal foundation for relational model operations. 2. and perhaps more important, it is used as a basis
CSC 74 Database Management Systems Topic #0: SQL Part A: Data Definition Language (DDL) Spring 00 CSC 74: DBMS by Dr. Peng Ning Spring 00 CSC 74: DBMS by Dr. Peng Ning Schema and Catalog Schema A collection
Course Notes on The Bases of the Relational Model Intuitive View of Relations Popular view of the relational model = information is structured as 2-dimensional tables of simple values (with lines, or rows,
More SQL: Complex Queries This chapter describes more advanced features of the SQL language standard for relational databases. 5.1 More Complex SQL Retrieval Queries Because of the generality and expressive
4. SQL - the Relational Database Language Standard 4.1 Introduction 4. SQL - the Relational Database Language Standard 4.1 Introduction Most relevant query languages development of special languages for
Information Systems SQL Nikolaj Popov Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria firstname.lastname@example.org Outline SQL Table Creation Populating and Modifying
CS 4700/6700 A Sample of Small Database Design Using Microsoft Access Company relational database schema from the textbook (Fundamentals of Database systems, 6 th Edition, by Ramez Elmasri and Shamkant
The Relational Algebra Relational set operators: The data in relational tables are of limited value unless the data can be manipulated to generate useful information. Relational Algebra defines the theoretical
Course Notes on SQL SQL: Introduction SQL: Summary of Presentation Bases of SQL Discussion of SQL features through examples Criticism of SQL Standardization SQL = another syntax for expressions of DRC,
SQL SQL SQL = Structured Query Language Standard query language for relational DBMSs History: Developed at IBM in late 70s 1 st standard: SQL-86 2 nd standard: SQL-92 3 rd standard: SQL-99 or SQL3, well
MAPPING RELATIONAL MODEL ER LECTURE 5 DATABASE TECHNOLOGY TDDB48 Slide 1 DESIGNING A RELATIONAL DATABASE SCHEMA This is the logical database design step. Many tools (CASE, etc) use ER diagrams or variations
Relational Model CS 377: Database Systems Relational Model First formal database model Introduced by Ted Codd in 1970 Conceptual basis of relational databases Simple and based on the mathematical relations
SS Chung Lab Assignment 0 1. Creating a Relational Database Schema from ER Diagram, Populating the Database and Querying over the database with SQL 1. Creating the COMPANY database schema using SQL (DDL)
9 More SQL: Assertions, Views, and Programming Techniques In the previous chapter, we described several aspects of the SQL language, the standard for relational databases. We described the SQL statements
New York University Computer Science Department Courant Institute of Mathematical Sciences Homework #5 Solutions Course Title: Database Systems Instructor: Jean-Claude Franchitti Course Number: CSCI-GA.2433-001
Oracle For Beginners Page : 1 3.GETTING STARTED WITH ORACLE8i Creating a table Datatypes Displaying table definition using DESCRIBE Inserting rows into a table Selecting rows from a table Editing SQL buffer
Database Systems I (Compulsory) INTRODUCTION This is one of the 4 modules designed for Semester 2 of Bachelor of Information Technology Degree program. CREDITS: 04 LEARNING OUTCOMES On completion of this
Data Base Management Systems (DBMS) Study Material (Objective Type questions with Answers) Shared by Akhil Arora Powered by www. your A to Z competitive exam guide Database Objective type questions Q.1
Database Query 1: SQL Basics CIS 3730 Designing and Managing Data J.G. Zheng Fall 2010 1 Overview Using Structured Query Language (SQL) to get the data you want from relational databases Learning basic
Relational Database Systems Part 01 Karine Reis Ferreira email@example.com Database System Database: is a collection of related data. represents some aspect of the real world is a logically coherent collection
Relational Database Languages Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG) Domain relational calculus QBE (used in Access) History of SQL Standards:
: Database Systems 1 (DBS 1) (Compulsory) 1. OUTLINE OF SYLLABUS Topic Minimum number of hours Introduction to DBMS 07 Relational Data Model 03 Data manipulation using Relational Algebra 06 Data manipulation
Oracle University Contact Us: +966 12 739 894 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training is designed to
4 Logical Design : RDM Schema Definition with SQL / DDL 4.1 SQL history and standards 4.2 SQL/DDL first steps 4.2.1 Basis Schema Definition using SQL / DDL 4.2.2 SQL Data types, domains, user defined types
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
Part 2: Semantic Data Modeling Junping Sun Database Systems 2-1 Phases of Database Design (Simplified) Miniworld DATABASE REQUIREMENTS COLLECTION AND ANALYSIS Database Requirements CONCEPTUAL DESIGN DBMS-independent
Structured Query Language (SQL) Introduction Commercial database systems use more user friendly language to specify the queries. SQL is the most influential commercially marketed product language. Other
Chapter (7) ER-to-Relational Mapping, and other Relational Languages Objectives How a relational database schema can be created from a conceptual schema developed using the ER models. We will look at the
Unit 43: Programming with SQL Learning Outcomes A candidate following a programme of learning leading to this unit will be able to: Create queries to retrieve information from relational databases using
A Brief Introduction to MySQL by Derek Schuurman Introduction to Databases A database is a structured collection of logically related data. One common type of database is the relational database, a term
Instant SQL Programming Joe Celko Wrox Press Ltd. INSTANT Table of Contents Introduction 1 What Can SQL Do for Me? 2 Who Should Use This Book? 2 How To Use This Book 3 What You Should Know 3 Conventions
CSC 742 Database Management Systems Topic #6: Database Design Spring 2002 CSC 742: DBMS by Dr. Peng Ning Mapping ER Diagrams to Relations Regular Entity Type Create a relation R Include simple attributes
Oracle University Contact Us: 1.800.529.0165 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This course is designed to deliver the fundamentals of SQL and PL/SQL along
Oracle University Contact Us: 1.800.529.0165 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database technology.
A First Book of C++ Chapter 2 Data Types, Declarations, and Displays Objectives In this chapter, you will learn about: Data Types Arithmetic Operators Variables and Declarations Common Programming Errors
Entity Relationship Modeling High Level Conceptual Design Language ER Modeling method of analyzing requirements results in conceptual schema schema is E R diagram data model independent can translate into
SQL ACCESS FOR SUPRA SERVER PDM SQL Reference Guide P25-9503-03 SQL Access for SUPRA Server PDM SQL Reference Guide Publication Number P25-9503-03 2006, 2007, 2009 Cincom Systems, Inc. All Rights Reserved
DDL Data types Numbers integer, smallint, bigint real, double precision Characters and Strings char(n): up to n characters, blank padded varchar(n): up to n characters, variable length Date & Time date
Database Design and Programming with SQL: Part 2 Learning Objectives This is the second portion of the Database Design and Programming with SQL course. In this portion, students implement their database
Netezza SQL Class Outline CoffingDW education has been customized for every customer for the past 20 years. Our classes can be taught either on site or remotely via the internet. Education Contact: John
Oracle SQL Course Summary Identify the major structural components of the Oracle Database 11g Create reports of aggregated data Write SELECT statements that include queries Retrieve row and column data
ER & EER to Relational Mapping Chapter 9 1 Figure 3.2 ER schema diagram for the company database. Fname Minit Lname Number Name Address N 1 WORKS_FOR Name Locations Sex Salary Ssn Bdate EMPLOYEE NumberOfEmployees
Oracle University Contact Us: 1.800.529.0165 Oracle Database 12c: Introduction to SQL Ed 1.1 Duration: 5 Days What you will learn This Oracle Database: Introduction to SQL training helps you write subqueries,
SQL Server An Overview SQL Server Microsoft SQL Server is designed to work effectively in a number of environments: As a two-tier or multi-tier client/server database system As a desktop database system
Oracle 10g PL/SQL Training Course Number: ORCL PS01 Length: 3 Day(s) Certification Exam This course will help you prepare for the following exams: 1Z0 042 1Z0 043 Course Overview PL/SQL is Oracle's Procedural
A Tutorial on MS Access Dongqiuye Pu firstname.lastname@example.org Xiangyu Fan email@example.com Weimao Ke firstname.lastname@example.org School of Information and Library Science University of North Carolina at Chapel Hill Oct 23
Oracle University Contact Us: + 38516306373 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
Working with DB2 UDB objects http://www7b.software.ibm.com/dmdd/ Table of Contents If you're viewing this document online, you can click any of the topics below to link directly to that section. 1. Introduction...
CS145 Lecture Notes #7 SQL Query & Modification Introduction SQL Structured Query Language Pronounced S-Q-L or sequel The query language of every commercial RDBMS Evolution of SQL standard: SQL89 SQL92
Relational Model CENG 351 1 Relational Database: Definitions Relational database: a set of relations Relation: made up of 2 parts: Instance : a table, with rows and columns. #Rows = cardinality, #fields
Outlines Data Modeling Using the Entity- Relationship Model Instructor: Chapter 6 Churee Techawut 1) Database design process 2) ER Model concepts 3) ER diagrams notation 4) Relationships and relationship
This Lecture Database Systems Lecture 5 Natasha Alechina The language, the relational model, and E/R diagrams CREATE TABLE Columns Primary Keys Foreign Keys For more information Connolly and Begg chapter
More on SQL Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan SELECT A1, A2,, Am FROM R1, R2,, Rn WHERE C1, C2,, Ck Interpreting a Query
DATABASE DESIGN - 1DL400 Spring 2015 A course on modern database systems http://www.it.uu.se/research/group/udbl/kurser/dbii_vt15/ Kjell Orsborn Uppsala Database Laboratory Department of Information Technology,
What is? 1. stands for Structured Query Language 2. lets you access and manipulate databases 3. is an ANSI (American National Standards Institute) standard Note: is not case sensitive. SELECT is the same
course: Database Applications (NDBI026) WS2015/16 RNDr. Michal Kopecký, Ph.D. Department of Software Engineering, Faculty of Mathematics and Physics, Charles University in Prague student duties final DB
Computational Finance and Risk Management Financial Data Access with SQL, Excel & VBA Guy Yollin Instructor, Applied Mathematics University of Washington Guy Yollin (Copyright 2012) Data Access with SQL,
SQL Development Using Oracle Course Summary Identify the major structural components of the Oracle Database 11g Create reports of aggregated data Write SELECT statements that include queries Retrieve row
Information Systems 2 Information Systems 2 1. Modelling Information Systems I: Databases Lars Schmidt-Thieme Information Systems and Machine Learning Lab (ISMLL) Institute for Business Economics and Information
CS1Ah Lecture Note 5 Java Expressions Many Java statements can contain expressions, which are program phrases that tell how to compute a data value. Expressions can involve arithmetic calculation and method
Relational Database: Additional Operations on Relations; SQL Greg Plaxton Theory in Programming Practice, Fall 2005 Department of Computer Science University of Texas at Austin Overview The course packet
DBMS LAB MANUAL PREPARED BY JAGRUTI SAVE 1 EXPERIMENT NO: 1 AIM: Preparing an ER diagram for given database and Conversion from ER diagram to tables THEORY: Database : A Database is a collection of interrelated
JAVA TYPES BASIC DATA TYPES GENERAL Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. Based on the data type
4 Simple Database Features Now we come to the largest use of iseries Navigator for programmers the Databases function. IBM is no longer developing DDS (Data Description Specifications) for database definition,
Create or modify tables or indexes by using a data-definition query In Microsoft Office Access 2007, it is easy to create and modify tables, constraints, and indexes in Design view, and to create relationships
SQL Introduction to SQL SQL functions fit into two broad categories: Data definition language (Table 1) Data manipulation language (Table 2) The goals of this lab are to understand: 1. The basic data types
Chapter 7 Structured Query Language (SQL) SQL DML Commands SQL DDL Commands SQL SELECT Used to extract data from a database This is a table called Persons from the Northwind database The command SELECT
Chapter (3) Data Modeling Using the Entity-Relationship Model Objectives Presenting the role of high-level conceptual data models in database design. Understanding the traditional approach of concentrating
Your consent to our cookies if you continue to use this website.