2. Course Content
321
5 64
7 8 9
Introduction to SQL
Basic concepts of
databases.
Relational database
objects.
Data types.
Queries
What is SQL?
What is DML?
The basic DML query
is SELECT, INSERT,
UPDATE, DELETE.
The basics of DDL
What is DDL?
CREATE, ALTER, DROP.
The concepts of user
restrictions, primary
and foreign keys.
JOINs
Internal connections.
External connections.
Review of
associations.
Nested queries
Nested queries.
Linked nested
queries.
Indexing
Btrees.
Consideration of all
kinds of indices.
Stored procedures
Views.
Conditional
constructions, loops,
processing of error
messages.
Stored procedures.
Functions.
Transactions. Triggers
Transactions.
Mechanisms of rollback
of transactions.
Triggers.
Aggregating functions
Group by
Having by
21. The basics of DDL
CREATE, ALTER, DROP.
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more
columns )
);
CREATE TABLE credit
(
currency_rate numeric(5,2) NOT NULL DEFAULT(1.0),
current_payment numeric(10,2) NOT NULL,
days_past_due integer NOT NULL,
debt numeric(10,2) NOT NULL,
client_id integer NOT NULL,
product_ref character(19) NOT NULL,
product_pan character(25),
CONSTRAINT credit_pkey PRIMARY KEY (client_id, product_ref)
)
3
22. The basics of DDL
CREATE, ALTER, DROP.
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more
columns )
);
CREATE TABLE credit
(
currency_rate numeric(5,2) NOT NULL DEFAULT(1.0),
current_payment numeric(10,2) NOT NULL,
days_past_due integer NOT NULL,
debt numeric(10,2) NOT NULL,
client_id integer NOT NULL,
product_ref character(19) NOT NULL,
product_pan character(25),
CONSTRAINT credit_pkey PRIMARY KEY (client_id, product_ref)
)
CREATE TABLE new_table_name AS
SELECT column1, column2,...
FROM existing_table_name
WHERE ....;
CREATE TABLE copy_credit AS
SELECT client_id, product_ref
FROM credit
WHERE current_payment =100
CREATE TABLE new_table_name AS
SELECT column1, column2,...
FROM existing_table_name
WHERE ....;
3
23. The basics of DDL
CREATE, ALTER, DROP.
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more
columns )
);
CREATE TABLE credit
(
currency_rate numeric(5,2) NOT NULL DEFAULT(1.0),
current_payment numeric(10,2) NOT NULL,
days_past_due integer NOT NULL,
debt numeric(10,2) NOT NULL,
client_id integer NOT NULL,
product_ref character(19) NOT NULL,
product_pan character(25),
CONSTRAINT credit_pkey PRIMARY KEY (client_id, product_ref)
)
CREATE TABLE new_table_name AS
SELECT column1, column2,...
FROM existing_table_name
WHERE ....;
CREATE TABLE copy_credit AS
SELECT client_id, product_ref
FROM credit
WHERE current_payment =100
CREATE TABLE new_table_name AS
SELECT column1, column2,...
FROM existing_table_name
WHERE ....;
SELECT column1, column2,…
INTO new_table_name
FROM existing_table_name
WHERE ....;
SELECT client_id, product_ref
INTO new_table_name
FROM credit
WHERE current_payment=100;
3