Rdbms SQL Basics
Rdbms SQL Basics
What is RDBMS ?
The Relational Database Model:
user
PK user_id
first_name
last_name
phone
nickname email
address PK phone_id
city PK email_id
province country_code
postal_code address number
country extension
web_url
company
department
picture
notes
Second Normal Form
Table must be in First Normal Form
Remove vertical redundancy
The same value should not repeat across rows
Composite keys
All columns in a row must refer to BOTH parts of the
key
Benefits
Increased storage efficiency
Less data repetition
Satisfying 2NF
user_phone
phone
user
PK,FK1 user_id
PK phone_id
PK user_id PK,FK2 phone_id
country_code
first_name extension
number
last_name
type
nickname
address
city
email province
postal_code user_company
PK address country company
PK,FK1 user_id
web_url
PK,FK2 company_id PK company_id
FK1 user_id picture
format notes
department name
Relational Query Languages
4/28/2014
Concept of SQL
4/28/2014
SQL Data Definition Language (DDL)
The Data Definition Language (DDL) part of SQL permits
database tables to be created or deleted. We can also define
indexes (keys), specify links between tables, and impose
constraints between database tables.
Union UNION
4/28/2014
SQL Database Tables
Syntax
SELECT column_name(s)
FROM table_name
SELECT LastName FROM Persons
LastName
Gives a result set like this:
Hansen
Svendson
Pettersen
The INSERT INTO Statement
The INSERT INTO statement is used to insert new rows into
a table.
Syntax
INSERT INTO table_name
VALUES (value1, value2,....)
You can also specify the columns for which you want to insert
data:
INSERT INTO table_name (column1, column2,...)
VALUES (value1, value2,....)
The Update Statement
UPDATE table_name
SET column_name = new_value
WHERE column_name = some_value
The Delete Statement
We want to change the address and add the name of the city:
UPDATE Person
SET Address = 'Stien 12', City = 'Stavanger'
WHERE LastName = 'Rasmussen'