Lecture Materials Week 9 (File Name) Flashcards
(36 cards)
SQL stands for
Structured Query Language
SQL was developed by this company in the late 70s
IBM
SQL is not a full-featured ___________ ________
programming language
SQL is a ____ ___________ for creating and processing database data/metadata
data sublanguage
SQL statements can be divided into 5 categories, they are:
DDL: Data definition language
DML: Data manipulation language
DCL: Data control language
TCL: Transaction control language
and SQL/PSM: Persistent stored modules statements
The ______ _____ statement is used to create relations
CREATE TABLE
Each column in a table is described with 3 parts:
Column name, data type, and optional constraints
Place these in the correct order
DataType
ColumnName
OptionalConstraint
ColumnName Datatype Optional Constraint
Place these in the correct order
Optional table constraint
CREATE TABLE newTableName
ColumnName DataType OptionalConstraint,
CREATE TABLE newTableName
ColumnName DataType Optional Constraint,
Optional table constraint
Constraints can be ______ __ the CREATE TABLE statement or can be added _____ using the _____ table statement
placed in, added after, ALTER Table
5 Different Column/table constraints
Primary key
Foreign key
NULL/NOT NULL
Unique
Check
The _______ keyword can be used to set initial values
Default
Implementing Cardinalities:
1:N relationship, parent optional
Set foreign key to NULL.
Implementing Cardinalities:
1:N relationship, parent required
Set foreign key to NOT NULL.
Implementing Cardinalities:
1:1 relationship, parent optional
Specify a foreign key UNIQUE constraint. Set foreign key to NULL.
Implementing Cardinalities:
1:1 relationship, parent required:
Specify foreign key UNIQUE constraint. Set foreign
key NOT NULL.
Casual relationship
Create a foreign key column, but do not
specify FOREIGN KEY constraint. If
relationship is 1:1, specify a foreign key
UNIQUE constraint.
You are making the attribute “WorkID” a primary key in the “Work” table, what would the statement be to create it?
CONSTRAINT WorkPK PRIMARY KEY( WorkdID )
You are making the “Title” and “Copy” attributes a unique key in the “Work” table, what would the statement be to do this?
CONSTRAINT WorkUK1 UNIQUE( Title, Copy )
You are making “ManufacturerID” a foreign key in the “Work” table, it will be referencing the “Manufacturer” table. What is the statement to do this?
CONSTRAINT ManfacturerFK FOREIGN KEY( ManfacturerID )
REFERENCES Manufacturer( ManufacturerID )
The SQL ALTER TABLE statement is used to
Change the structure of an existing table.
The ALTER TABLE statement can not only add, remove or change columns, but can also
add or remove constraints
ALTER TABLE statement that will add a column named MyColumn to the Customer table - Char(5), NULL
ALTER TABLE Customer
ADD myColumn Char(5) NULL:
ALTER TABLE statement that will drop MyColumn from the customer table
ALTER TABLE Customer
DROP COLUMN MyColumn;