Step-by-step introduction to databases
Database Table
A database usually contains one or more tables. Each table is identified by a name (for example, "customer" or "order "). A table contains records (rows) with data ).
The following example shows a table named "Persons:
Id |
LastName |
FirstName |
Address |
City |
1 |
Adams |
John |
Oxford Street |
London |
2 |
Bush |
George |
Th Avenue |
New York |
3 |
Carter |
Thomas |
Changan Street |
Beijing |
The table above contains three records (each corresponding to one person) and five columns (Id, last name, name, address, and city ).
SQL statement
Most of the work you need to execute on the database is completed by SQL statements.
The following statement selects the data in the LastName column from the table:
SELECT LastName FROM Persons
The result set is similar to the following:
LastName |
Adams |
Bush |
Carter |
In this tutorial, we will explain various SQL statements for you.
Important
Be sure to remember that SQL is not case sensitive!
What is the semicolon next to an SQL statement?
Some database systems require the use of semicolons at the end of each SQL command. Do not use semicolons in our tutorial.
A semicolon is a standard method used to separate each SQL statement in the database system. In this way, you can execute more than one statement in the same request to the server.
If you are using MS Access and SQL Server 2000, you do not have to use a semicolon after each SQL statement, but some database software requires that you use a semicolon.
SQL dml and DDL can divide SQL into two parts: data operation language (DML) and Data Definition Language (DDL ).
SQL (Structured Query Language) is the syntax used to execute queries. However, the SQL language also contains the syntax used to update, insert, and delete records.
The query and update commands constitute the DML part of SQL:
- SELECT-obtain data from a database table
- UPDATE-UPDATE data in the database table
- DELETE-DELETE data from a database table
- Insert into-INSERT data to a database table
The Data Definition Language (DDL) Section of SQL enables us to create or Delete tables. We can also define indexes (KEYS), define links between tables, and apply constraints between tables.
The most important DDL statements in SQL:
- Create database-CREATE a new DATABASE
- Alter database-modify DATABASE
- Create table-CREATE a new TABLE
- Alter table-Change Database TABLE
- Drop table-delete a TABLE
- Create index-create index (search key)
- Drop index-delete an INDEX