Topic 7 An Introduction To SQL
Topic 7 An Introduction To SQL
Chapter 7
Introduction to Structured Query Language
(SQL)
Objectives
2
information
Introduction to SQL
Data definition commands
Data manipulation commands
Select queries
Advanced data definition commands
Virtual tables: creating a View
Joining database tables
Authentication
DBMS verifies that only registered users are able to
access database
Log on to RDBMS using user ID and password created
by database administrator
Schema
Group of database objects that are related to each other
INSERT
SELECT
COMMIT
UPDATE
ROLLBACK
DELETE
INSERT
Used to enter data into table
Syntax:
INSERTINTO columnname
VALUES (value1, value2, … , valueN);
SELECT
Used to list contents of table
Syntax:
SELECT columnlist
FROM tablename;
UPDATE
Modify data in a table
Syntax:
UPDATE tablename
SET columnname = expression [, columnname =
expression]
[WHERE conditionlist];
If more than one attribute is to be updated in row,
separate corrections with commas
ROLLBACK
Undoes changes since last COMMIT
Brings data back to prechange values
Syntax:
ROLLBACK;
COMMIT and ROLLBACK only work with
commands to add, modify, or delete table rows
DELETE
Deletes a table row
Syntax:
DELETE FROM tablename
[WHERE conditionlist ];
WHERE condition is optional
If WHERE condition is not specified, all rows from
specified table will be deleted
INSERT
Inserts multiple rows from another table (source)
Uses SELECT subquery
Subquery: query embedded (or nested or inner)
inside another query
Subquery executed first
Syntax:
INSERT INTO tablename SELECT columnlist FROM
tablename;
DROP
Deletes table from database
Syntax:
DROP TABLE tablename;
Can drop a table only if it is not the “one” side of
any relationship
Otherwise, RDBMS generates an error message
Foreign key integrity violation