Professional Documents
Culture Documents
Navathe Slide 8- 1
Chapter 8
SQL-99: SchemaDefinition,
Constraints, and Queries and Views
VARCHAR2
The VARCHAR2 data type stores variable-length character strings.
VARCHAR
The VARCHAR data type is currently synonymous with the
Date type:
Date
storing date data.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 9
CREATE TABLE
CREATE TABLE table_name (
column1 <datatype> <constraint>,
column2 <datatype> <constraint>,
...
column_n <datatype> <constraint>
);
Table created.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 13
Describe in SQL
SQL>desc employee
Name Null? Type
----------------------------------------- -------- ----------------------------
FNAME NOT NULL VARCHAR2(15)
MINIT CHAR(1)
LNAME NOT NULL VARCHAR2(15)
SSN NOT NULL CHAR(9)
BDATE DATE
ADDRESS VARCHAR2(30)
SEX CHAR(1)
SALARY NUMBER(10,2)
SUPERSSN CHAR(9)
DNOCopyright © 2007 Ramez Elmasri and Shamkant B. Navathe
NOT NULL NUMBER(4) Slide 8- 14
CREATE TABLE
Specifies a new base relation by giving it a name, and
specifying each of its attributes and their data types
(INTEGER, FLOAT, DECIMAL(i,j), CHAR(n),
VARCHAR(n))
A constraint NOT NULL may be specified on an attribute
CREATE TABLE DEPARTMENT (
DNAME VARCHAR(10) NOT NULL,
DNUMBER NUMBER(3) PRIMARY KEY,
MGRSSN CHAR(9),
MGRSTARTDATE DATE);
1 row created.
Example:
SQL>insert into employee
values(‘&fname',‘&minit',‘&lname',‘&ssn',‘&bdate',‘&address',
‘&gender',&salary,‘&superssn',&dno);
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
Q1:SELECT SSN
FROM employee
WHERE DNAME='Research’
• Query modification:
– Present the view query in terms of a query on the
underlying base tables
• Disadvantage:
– Inefficient for views defined via complex queries
• Especially if additional queries are to be applied to
the view within a short time period
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 9- 90
Efficient View Implementation
• View materialization:
– Involves physically creating and keeping a
temporary table
• Assumption:
– Other queries on the view will follow
• Concerns:
– Maintaining correspondence between the base
table and the view when the base table is updated
• Strategy:
– Incremental update