|
|
SQL Data Manipulation Language (DML) |
| |
SQL (Structured Query Language) is a syntax for executing queries. But the SQL language also includes a syntax to update, insert, and delete records. |
| |
These query and update commands together form the Data Manipulation Language (DML) part of SQL: |
| |
- SELECT - extracts data from a database table
- UPDATE - updates data in a database table
- DELETE - deletes data from a database table
- INSERT INTO - inserts new data into a database table
|
| |
SQL Data Definition Language (DDL) |
| |
The Data Definition Language (DDL) part of SQL permits database tables to be created or deleted. We can also define indexes (keys), specify links between tables, and impose constraints between database tables. |
| |
The most important DDL statements in SQL are: |
| |
- CREATE TABLE - creates a new database table
- ALTER TABLE - alters (changes) a database table
- DROP TABLE - deletes a database table
- CREATE INDEX - creates an index (search key)
- DROP INDEX - deletes an index
|
| |
The SQL SELECT Statement |
| |
The SELECT statement is used to select data from a table. The tabular result is stored in a result table (called the result-set). |
| |
Syntax |
| |
| SELECT column_name(s)
FROM table_name |
|
| |
Note: SQL statements are not case sensitive. SELECT is the same as select. |
| |
SQL SELECT Example |
| |
| SELECT LastName,FirstName FROM Persons |
|
| |
The database table "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 result |
| |
| LastName |
FirstName |
| Koteswara Rao |
Parala |
| Raja Ramesh |
Prathiwada |
| Ashok |
Kosuri |
| Vivek |
Chavanaboina |
| Abbas |
MD |
|
| |
Select All Columns |
| |
To select all columns from the "Persons" table, use a * symbol instead of column names, like this: |
| |
|
| |
Result |
| |
| 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 Result Set |
| |
The result from a SQL query is stored in a result-set. Most database software systems allow navigation of the result set with programming functions, like: Move-To-First-Record, Get-Record-Content, Move-To-Next-Record, etc. |
| |
Programming functions like these are not a part of this tutorial. To learn about accessing data with function calls, please learn ADO tutorial. |
| |
Semicolon after SQL Statements? |
| |
Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server.
Some SQL tutorials end each SQL statement with a semicolon. Is this necessary? We are using MS Access and SQL Server 2000 and we do not have to put a semicolon after each SQL statement, but some database programs force you to use it. |
| |
| |
| |
| |