Introduction to SQL

What is SQL?


SQL was developed by IBM in the 1970s for its mainframe platform. A few years later, SQL became standardized by both the American National Standards Institute (ANSI-SQL) and the International Organization for Standardization (ISO-SQL). According to ANSI, SQL is pronounced "es queue el", but many software and database developers with MS SQL Server experience pronounce it "continue".


What is an RDBMS?


A relational database management system is software used to store and manage data in database objects called tables. A relational database table is a tabular data structure organized into columns and rows. Table columns, also known as table fields, have unique names and various attributes defining the column type, default value, indexes, and several other column characteristics. The rows of a relational database table are the actual data items.


The most popular SQL RDBMS


The most popular RDBMS are MS SQL Server by Microsoft, Oracle by Oracle Corp., DB2 by IBM, MySQL by MySQL, and MS Access by Microsoft. Most commercial database vendors have developed their proprietary SQL extensions based on the ANSI-SQL standard. For example, the version of SQL used by MS SQL Server is called Transact-SQL or simply T-SQL, Oracle's version is called PL/SQL (short for Procedural Language/SQL), and MS Access uses Jet-SQL.


What can you do with SQL?


SQL queries use the SELECT SQL keyword, which is part of the Data Query Language (DQL). If we have a table called "Orders" and you want to select all items whose order value is greater than $100, sorted by order value, you can do this with the following SQL SELECT query:


SELECT OrderID, ProductID, CustomerID, OrderDate, OrderValue


From orders


WHERE OrderValue > 200


ORDER BY OrderValue;


The SQL FROM clause specifies which table(s) we are getting data from. The SQL WHERE clause specifies the search criteria (in our case, get only records with an OrderValue greater than $200). The ORDER BY clause specifies that the returned data must be ordered by the OrderValue column. The WHERE and ORDER BY clauses are optional.


o You can manipulate data stored in relational database tables using the SQL INSERT, UPDATE and DELETE keywords. These three SQL statements are part of the Data Manipulation Language (DML).


-- To insert data into a table called "Orders", you can use an SQL statement similar to the one below:


INSERT INTO OrderValue (ProductID, CustomerID, OrderDate, OrderValue)


VALUES (10, 108, '12/12/2007', 99.95);


-- To modify the data in the table, you can use the following command:


UPDATE orders


SET OrderValue = 199.99


WHERE CustomerID = 10 AND OrderDate = '12/12/2007';


-- To delete data from a database table, use a command like the one below:


DELETE orders


WHERE CustomerID = 10;


o You can create, modify, or drop database objects (examples of database objects are database tables, views, stored procedures, etc.) using the SQL keywords CREATE, ALTER, and DROP. For example, you can use the following SQL statement to create the "Orders" table:


CREATE orders


(


orderID INT IDENTITY(1, 1) PRIMARY KEY,


ProductID INT,


Customer ID,


Date of order DATE,


OrderValue currency


)


o You can control the permissions of database objects using the GRANT and REVOKE keywords, which are part of the Data Control Language (DCL). For example, to allow a user with the username "User1" to select data from the "Orders" table, you can use the following SQL statement:


MAKE SELECT ORDERS User1


SQL

SQL , also pronounced as See-Quel, stands for Structured Query Language, letting you access, manipulate, create, delete, update, and retriev...