![]() |
Data are entered into and removed from a table in sql by use of the insert and delete commands. Delete allows users to specify conditions under which records are erased selectively. Truncate removes all rows from a table, performing more quickly than delete. Create and drop produce and remove tables. Alter modifies tables by adding or revising columns. Rename changes the name of a table. Update modifies data already residing in a database. Enable and disable produce and remove integrity constraints - rules that restrict the range of valid values for a column. Lock table allows a table to be shared among users without corruption (loss of integrity). Analyze lets you collect statistics about a table and test for possible corruption. Connect and disconnect allow programs in one database to access records in another. Grant and revoke extend and rescind system and table privileges to/from users. The most important sql command is select, used to return specified values. Without the ability to retrieve data, a system for their management would be of no value. Intersect combines two queries and returns only those rows that satisfy both select statements; union returns any rows satisfying either. Explain plan allows you to view the steps taken in query execution. Like performs pattern matching, a process of searching through the rows of a column for values that look like a specified pattern. This feature can play an important role in retrieving partially remembered records of items such as products, names and addresses. A major strength of sql is the varied set of record preservation commands made available to both users and db managers. Commit preserves changes made within a session. Rollback reverses any alterations made since the last commit. [Truncate is faster than delete because it generates no rollback information.] Savepoint allows for partial rollbacks. So-called implicit commits occur when certain commands are used, including create/drop table, grant/revoke, connect/disconnect and alter. Archive_log allows managers to control the activity of redo files, non-permanent transaction records. Audit and no audit return and block records of user activity. [Archive_log and audit/no audit both force implicit commits.] |
Sql also provides a number of pre-defined operations called functions for manipulating and describing data. These can be divided roughly in two ways - by data type (character, number, date) or by value number (single-value operate on all data types; group-value work only with number data). Character functions include a variety of "cut and paste" techniques such as substr which clips a piece out of a string, and concatenate (represented by the symbol ||) which sticks two strings together. Some other character functions are replace and translate which use logic to revise strings, instr which searches for a specified set of characters, and soundex which finds words that sound like an example string. Number functions act on single values to perform mathematical, comparative and trigonometric operations, on group values for computational and statistical procedures, and also on lists of values, choosing one member (e.g., greatest or least) from a set of columns. [Group functions work on a set of rows.] Date functions are used to compute (e.g., adding a number of months) and to compare (e.g., greatest and least). Conversion functions either recast one data type into another or perform some technical alteration. One function defying categorization is decode which uses logic to test columns or computations for their values and then performs some action (e.g., forcing row-by-row changes) based on those values. This is a very powerful tool which can be used to produce spreads of values (e.g., aging of invoices), perform sophisticated calculations, or even effectively flip tables on their sides. |
|||