STRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGE Introduction SQL (Structured Query Language) is a nonprocedural language for relational database. It is generally a medium which is used to communicate to the DBMS. SQL commands consist of English-like statements which are used to query, insert, update, and delete data. Commercial database management systems allow SQL to be used in two distinct ways:
1. SQL commands can be typed at the command line directly. The DBMS interprets and processes the SQL commands immediately, and the results are displayed. This method of SQL processing is called interactive SQL. 2. Programmatic SQL. Here, SQL statements are embedded in a host language such as COBOL, FORTRAN, C, etc. SQL needs a host language because SQL is not a really complete computer programming language as such because it has no statements or constructs that allow branch or loop. The host language provides the necessary looping and branching structures and the interface with the user, while SQL provides the statements to communicate with the DBMS. Some of the features of SQL are: • SQL is a language used to interact with the database. • SQL is a data access language.
• SQL is based on relational tuple calculus. • SQL is a standard relational database management language. Note: SQL is referred to as nonprocedural database language, since, when we want to retrieve data from the database; you need to tell SQL what data to be retrieved, rather than how to retrieve it. The DBMS will take care of locating the information in the database. Commands in SQL SQL commands can be classified in to three types: i). Data Definition Language commands (DDL) ii).
Data Manipulation Language commands (DML) iii).Data Control Language commands (DCL) DDL: – DDL commands are used to define a database, including creating, altering, and dropping tables and establishing constraints. DML: – DML commands are used to maintain and query a database, including updating, inserting, modifying, and querying data. DCL: – DCL commands are used to control a database including administering privileges and saving of data. DCL commands are used to determine whether a user is allowed to carry out a particular operation or not. The ANSI standard groups these commands as being part of the DDL. The classification of commands in SQL is shown below. BIT 2206 Application Programming II ~Wainaina Page 2 of 6 1. SQL DDL Operations i) CREATE–CREATE ii) DELETE–DROP iii) MODIFY–ALTER Page | 2 Note: Database, table, index, schema, view, alias, UDF, UDT, trigger, event monitor, buffer pool, table