Ch 3: Intro to SQL Flashcards
3 Basic
Integrity Constraints
that can be defined in a Relation
primary key( Aj1, Aj2, … , Ajm)
Specifies given attributes as the primary key (all together)
Primary key attributes must be non-null and unique
foreign key( Ak1, Ak2, … , Akn) references Relation_S
Attributes must be the Primary Key of some tuple in the other relation
not null
Added to a specific attribute
example: name varchar(20) not null,
Important Parts/Features
of the SQL Language
(7)
- Data Definition Language (DDL)
- Data Manipulation Language (DML)
- Integrity
- View Definition
- Transaction Control
- Embedded SQL/Dynamic SQL
- Authorization
SQL Features:
Data Definition Language( DDL )
Commands for
- defining relational schemas
- modifying relational schemas
SQL Features:
Data Manipulation Language( DML )
Commands for:
- Querying data from the database
- Insert/delete tuples
- Modify tuples
SQL Features:
Integrity
Part of the DDL part of SQL
SQL provides commands for specifying Integrity Constraints
Also prevents updates from violating Integrity Constraints
SQL Features:
View Definition
SQL includes commands for
Defining Views
Part of being DDL
SQL Features;
Transaction Control
Commands for specifying the
beginning and end
of transactions
SQL Features:
Embedded SQL/Dynamic SQL
Defines how SQL statements can be
embedded within
general purpose languages
SQL Features:
Authorization
Includes commands for specifying
Access Rights
to relations and views
Two Aspects of
SQL as a Language
The SQL Language provides functionality for:
- Data Definition (DDL)
- Declaring and modifying database schemas
- Data Manipulation (DML)
- Operations for working with actual data
- Queries and modifications of tuples
Three kinds of Relations
in SQL
-
Stored Relations
- Called Tables
- kind of relation we deal with normally
- relations that are stored in the database
-
Views
- relations defined by a computation
- not stored
- constructed in whole or part when needed
-
Temporary Tables
- constructed by the SQL language when executing queries/modificatons
- thrown away after query, not stored
SQL Statement
to Define a Relation Schema
CREATE TABLE
- Gives a name for the table, its attributes and their data types
- Also allows declaring a key, or several, for a relation
- Allows constraint and index declarations, among others
SQL Primitive Data Types
CHAR(n), VARCHAR(n)
BIT(n), BITVARYING(n)
BOOLEAN
INT, or INTEGER
FLOAT, or REAL, DOUBLE PRECISION
DECIMAL( n, d)
DATE
TIME
SQL Example:
Declare this schema in SQL:
Movies( title: string, year:integer, genre: string)
CREATE TABLE Movies (
title CHAR(100),
year INT,
genre CHAR(10)
);
end with semicolon, each attribute has the form:
name TYPE
The SQL DDL
allows Specification of
What Relation Properties?
- Schema for each relation
- Types of Values associated with each attribute
- Integrity Constraints on values
- Set of Indices to be maintained for each relation
- Security and Authorization info for each relation
- Physical Storage Structure of each relation on disk