Since ISO and ANSI are two of the major international standards setting institutions, a standard that is adopted by both of them will be widely used by software manufacturers and thus, end users.
SQL is a complete database language because it is both a data definition language (DDL) and a data manipulation language (DML). It can create a relational database, query it, and manipulate the data in the database.
SQL is not a complete programming language since it cannot be used to write computer programs and procedures. However, SQL can be embedded in standard programming languages such as COBOL and C.
One of the major operational advantages of a relational DBMS is that DDL statements (data definition statements such as creating a table) can be executed at any time. Earlier DBMSs often require halting the entire system to create a new table, views, and indexes.
A base table is an autonomous, named table. It is autonomous because it exists in its own right. Views are derived from one or more base tables and actually do not exist independently of the base table. A view is also called a virtual table.
The primary key is used to uniquely identify any record of a table and is typically the primary index by which a table is searched. A unique key also uniquely identifies a table, but it is only used for additional indexes to the table.
An index is an ordered set of pointers to rows of a base table. It stores data about the position of the data in a certain column of a base table. Indexes are used to accelerate data access and ensure uniqueness.
The three choices for the ON DELETE command are: restrict, cascade, set null. The restrict option does permit deletion of a primary key when there are matching foreign keys in a related table. The cascade option automaticallydeletes all rows in a related table with matching foreign keys. The set null option sets all corresponding rows to null. The following table shows the advantages and disadvantages of all three options.
Option | Advantages | Disadvantages |
RESTRICT | * referential integrity
* no accidental loss of records |
* update is cumbersome: each value of the corresponding foreign key must be deleted before one value of a primary key can be deleted |
CASCADE | * referential integrity
* convenient update |
* all related records are lost, some data might be lost accidentally |
SET NULL | * convenient update
* no accidental loss of records |
* referential integrity: possibly many useless records with null values as foreign key |
(To answer these questions we assume US data. In other countries the data format might vary slightly)
The command DROP TABLE would erase the entire table. Deleting all rows, however, would leave an empty table.
A view can be created for a variety of reasons:
The view definition is stored in the systems catalogue and the view is actually created only when it is referenced in a query.
CREATE UNIQUE INDEX firmname ON shr (shrfirm);
a. No, it would not make sense to create a unique index for PE since two companies might have the same PE.
When two tables are connected using Product, each row of one table is concatenated with each row of the other table. Join combines only those rows with matching columns (typically a primary key - foreign key match).
An equijoin table contains two identical columns. If one of these two columns is dropped, the remaining table is called a natural join.
It would be wise to choose the alternative with the simple subquery since it would take less time to execute. A correlated subquery must be executed more than once and thus takes more time.
GRANT SELECT, INSERT ON nation TO hui-tze;
GRANT UPDATE(phonenum) ON CUSTOMER TO lana;
REVOKE ALL ON tablename FROM william;
(This has to be repeated for each table for which Chris has been granted privileges)
GRANT SELECT ON address TO chris WITH GRANT OPTION;
SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME REGEXP 'Sale';
SELECT TABLE_NAME, CREATE_TIME FROM TABLES WHERE YEAR(CREATE_TIME) = YEAR(CURRENT_DATE) - 1;
SELECT CHARACTER_MAXIMUM_LENGTH FROM COLUMNS WHERE COLUMN_NAME ='City' AND TABLE_SCHEMA = 'ClassicModels';
SELECT TABLE_NAME, COLUMN_NAME FROM COLUMNS WHERE DATA_TYPE ='SMALLINT';
SQL can be used as an interactive query language or embedded in an application program.
DELIMITER // CREATE PROCEDURE increaseCredit ( IN amount DECIMAL(5), IN countryIn CHARACTER(25)) LANGUAGE SQL BEGIN UPDATE Customers SET creditLimit = creditLimit + amount WHERE country = countryIn; END //
SQL processes one table at a time while COBOL processes one record at a time. Thus, COBOL uses a loop to process each record of a table.
This page is part of the promotional and support
material for Data Management (open edition) by Richard T. Watson For questions and comments please contact the author |