|
SQL INTRODUCTION |
|
| SQL (Structured Query Language) is a database sublanguage for querying and modifying relational databases. It was developed by IBM Research in the mid 70's and standardized by ANSI in 1986. |
| |
The Relational Model defines two root languages for accessing a relational database -- Relational Algebra and Relational Calculus. Relational Algebra is a low-level, operator-oriented language. Creating a query in Relational Algebra involves combining relational operators using algebraic notation. Relational Calculus is a high-level, declarative language. Creating a query in Relational Calculus involves describing what results are desired. |
| |
SQL is a version of Relational Calculus. The basic structure in SQL is the statement. Semicolons separate multiple SQL statements. |
| |
What is SQL? |
| |
- SQL stands for Structured Query Language
- SQL allows you to access a database
- SQL is an ANSI standard computer language
- SQL can execute queries against a database
- SQL can retrieve data from a database
- SQL can insert new records in a database
- SQL can delete records from a database
- SQL can update records in a database
- SQL is easy to learn
|
| |
| SQL is a Standard |
| |
SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems. SQL statements are used to retrieve and update data in a database. SQL works with database programs like MS Access, DB2, Informix, MS SQL Server, Oracle, Sybase, etc. |
| |
Unfortunately, there are many different versions of the SQL language, but to be in compliance with the ANSI standard, they must support the same major keywords in a similar manner (such as SELECT, UPDATE, DELETE, INSERT, WHERE, and others). |
| |
Note: Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard! |
| |
SQL Database Tables |
| |
A database most often contains one or more tables. Each table is identified by a name (e.g. "Customers" or "Orders"). Tables contain records (rows) with data. |
| |
Below is an example of a table called "Persons": |
| |
| LastName |
FirstName |
Address |
City |
| Koteswara Rao |
Parala |
Chimakurthy |
Ongole |
| Raja Ramesh |
Prathiwada |
Nellore |
Nellore |
| Ashok |
Kosuri |
Nellore |
Nellore |
| Vivek |
Chavanaboina |
Nellore |
Nellore |
| Abbas |
MD |
Maddipadu |
Ongole |
|
| |
The table above contains three records (one for each person) and four columns (LastName, FirstName, Address, and City). |
| |
SQL Queries |
| |
With SQL, we can query a database and have a result set returned. |
| |
A query like this: |
| |
| SELECT LastName FROM Persons |
|
| |
Gives a result set like this: |
| |
| LastName |
| Koteswara Rao |
| Raja Ramesh |
| Ashok |
| Vivek |
| Abbas |
|
| |
Note: Some database systems require a semicolon at the end of the SQL statement. We don't use the semicolon in our tutorials. |
| |
| |
| |