Database PDF
Database PDF
(SQL)
Introduction to SQL
• 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
• CREATE SCHEMA AUTHORIZATION
{creator};
• Command is seldom used directly
• INSERT
• SELECT
• COMMIT
• UPDATE
• ROLLBACK
• DELETE
• INSERT
• Used to enter data into table
• Syntax:
• INSERT INTO tablename (columnnames)
VALUES (value1, value2, … , valueN);
• SELECT
• Used to list contents of table
• Syntax:
SELECT columnlist
FROM tablename;
• Columnlist represents one or more attributes, separated
by commas
• Asterisk can be used as wildcard character to list all
attributes
Database Systems, 10th Edition 19
Updating Table Rows
• UPDATE
• Modify data in a table
• Syntax:
UPDATE tablename
SET columnname = expression [, columnname = expression]
[WHERE conditionlist];
• DELETE
• Deletes a table row
• Syntax:
DELETE FROM tablename
[WHERE conditionlist ];
• 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
Database Systems, 10th Edition 36
Additional SELECT Query
Keywords
• Logical operators work well in the query environment
• SQL provides useful functions that:
• Count
• Find minimum and maximum values
• Calculate averages, etc.
• SQL allows user to limit queries to:
• Entries having no duplicates
• Entries whose duplicates may be grouped
Database Systems, 10th Edition 37
Ordering a Listing
• ORDER BY clause is useful when listing order is
important
• Syntax:
SELECT columnlist
FROM tablelist
[WHERE conditionlist]
[ORDER BY columnlist [ASC | DESC]];
• Ascending order by default
Database Systems, 10th Edition 38
Listing Unique Values