Lecture 8. Advanced SQL
Lecture 8. Advanced SQL
2. Describe what a database is, the various types of databases, and why they are valuable assets for decision
making
8-3 Manipulate the structure of existing tables to add, modify, and remove columns and constraints
8-4 Use SQL to do data manipulation (insert, update, and deleterows of data)
8-6 Use procedural SQL to create triggers, stored procedures, and procedural SQL functions
If you are using an enterprise RDBMS, you must be authenticated by the RDBMS before
you can start creating tables.
Authentication The process through which a DBMS verifies that only registered users can access the
database.
To be authenticated, you must log on to the RDBMS using a user ID and a password created by the database
administrator.
a schema is a logical group of database objects—such as tables and indexes—that are related to each other
A single database can hold multiple schemas that belong to different users or applications.
Schemas are useful in that they group tables by owner (or function) and enforce a first level of security by
allowing each user to see only the tables that belong to that user
CREATE TABLE A SQL command that creates a table’s structures using the characteristics and attributes given.
SQL provides a way to rapidly create a new table based on selected columns and rows of an existing table
using a subquery.
CREATE INDEX A SQL command that creates indexes on the basis of a selected attribute or attributes
indexes can be used to improve the efficiency of searches and to avoid duplicate column values
when you declare a primary key, the DBMS automatically creates a unique index
Using the CREATE INDEX command, SQL indexes can be created on the basis of any selected attribute.
DROP INDEX A SQL command used to delete database objects such as tables, views, indexes, and users.
ALTER TABLE The SQL command used to make changes to table structure. When the command is followed by
a keyword (ADD, ALTER, or MODIFY), it adds a column or changes column characteristics.
COMMIT The SQL command that terminates a transaction by permanently saving data changes to a
database.
The COMMIT command permanently saves all changes—such as rows added, attributes modified, and rows
deleted—made to any table in the database
UPDATE A SQL command that allows attribute values to be changed in one or more rows of a table.
DELETE A SQL command that allows data rows to be deleted from a table.
ROLLBACK A SQL command that restores the database table contents to the condition that existed after the
ROLLBACK;
If you have not yet used the COMMIT command to store the changes permanently in the database, you can
restore the database to its previous condition with the ROLLBACK command.
COMMIT and ROLLBACK work only with data manipulation commands that add, modify, or delete table rows
View A virtual table based on a SELECT query that is saved as an object in the database.
CREATE VIEW A SQL command that creates a logical, “virtual” table. The view can be treated as a real table.
persistent storage module (PSM) A block of code with standard SQL statements and procedural extensions
that is stored and executed at the DBMS server.
The PSM represents business logic that can be encapsulated, stored, and shared among multiple database
users.
A PSM lets an administrator assign specific access rights to a stored module to ensure that only authorized
users can use it.
Procedural SQL An extension of the SQL programming language, such as PL/SQL or TSQL, that add
procedural programming capabilities, such as variable and logical flow control, to SQL and is designed to run
12/19/2024 Database System Design, Implementation And Management 45
8-7a Stored Procedures
Stored procedures help reduce code duplication by means of code isolation and code sharing (creating
Trigger A procedural SQL code that is automatically invoked by the relational database management system
when a data manipulation event occurs.
For example, if a product’s quantity on hand is updated when the product is sold, the system should
automatically check whether the quantity on hand falls below its minimum allowable quantity.
To demonstrate that process, use the PRODUCT table in Figure 8.22. Note the use of the minimum quantity
(P_MIN) and product reorder flag (P_REORDER) columns.
The P_MIN indicates the minimum quantity on hand allowable before restocking an item.
The P_REORDER column is a numeric field that indicates whether the product needs to be reordered (1 - Yes,
- 5 No).
The initial P_REORDER values are set to 0 (No) to serve as the basis for the initial trigger development.