Structured Query Language (SQL) Updated
Structured Query Language (SQL) Updated
(SQL)
B.Tech 5th CE
Dr. Neelam Duhan
(Associate Prof, CE)
◼ Catalog
◼ A set of schemas that constitute the description of a database
◼ Schema
◼ The structure that contains descriptions of objects created by a user
(base tables, views, constraints)
◼ Data Definition Language (DDL)
◼ Commands that define a database, including creating, altering, and
dropping tables and establishing constraints
◼ Data Manipulation Language (DML)
◼ Commands that maintain and query a database
◼ Data Control Language (DCL)
◼ Commands that control a database, including administering
privileges and committing data
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
A simplified schematic of a typical SQL environment, as
described by the SQL: 2008 standard
12
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
SQL Data Types
Example
Name CHAR(20)
Max Chars= 255
Name VARCHAR(40)
Max Chars= 4000
Salary NUMBER(4,2)
Max Precision= 38 digits
Salary INT
Level BOOLEAN
Date DATE Stores date in the format of system Date, format DateofBirth DATE
may be YYYY-MM-DD
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
DDL, DML, DCL, and the database development process
14
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
SQL Database Definition
◼ Data Definition Language (DDL)
◼ Major CREATE statements:
◼ CREATE SCHEMA–defines a portion of the
database owned by a particular user
◼ CREATE TABLE–defines a new table and its
columns
◼ CREATE VIEW–defines a logical table from one or
more tables or views
◼ Other CREATE statements: CHARACTER SET,
COLLATION, TRANSLATION, ASSERTION,
DOMAIN
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Steps in Table Creation
1. Identify data types for attributes
2. Identify columns that can and cannot be null
3. Identify columns that must be unique (candidate keys)
4. Identify primary key–foreign key mates
5. Determine default values
6. Identify constraints on columns (domain specifications)
7. Create the table and associated indexes
◼ EMPLOYEE.LNAME, DEPARTMENT.DNAME
◼ Query 8: For each employee, retrieve the employee's name, and the
name of his or her immediate supervisor.
Q1C: SELECT *
FROM EMPLOYEE
WHERE DNO=5
Q1D: SELECT *
FROM EMPLOYEE, DEPARTMENT
WHERE DNAME='Research' AND
DNO=DNUMBER