SQL is a standard computer language for accessing and manipulating databases.
SQL是一种标准的计算机语言,它可以用来访问和操作数据库
What is SQL?
什么是SQL?
- SQL stands for Structured Query Language
SQL代表结构化查询语言 - SQL allows you to access a database
SQL能让你访问到数据库 - SQL is an ANSI standard computer language
SQL为ANSI标准计算机语言 - SQL can execute queries against a database
SQL可以针对数据库执行查询 - SQL can retrieve data from a database
SQL可以回复来自数据库的信息 - SQL can insert new records in a database
SQL能在数据库中插入一条新的记录 - SQL can delete records from a database
SQL能够删除数据库中的记录 - SQL can update records in a database
SQL能够更新数据库里的信息 - SQL is easy to learn
SQL并不难学
SQL is a Standard - BUT....
SQL虽为标准 - 但是...
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.
SQL是ANSI体系中标准的数据库访问以及处理语言。SQL可以使用在像MS Access,DB2,Informix,MS SQL Server,Oracle,Sybase,等等一些数据库上。
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).
但它依然有多种版本,不过他们在关键字的使用上还是遵循了ANSI所规定的(比如SELECT,UPDATE,DELETE,INSERT,WHERE以及其他的一些)
Note: Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard!
注意:大多数数据库程序都带有属于他们自身特色的扩展属性。
SQL Database Tables
SQL数据表
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":
下面就是一个名为"Persons"的数据库表格:
LastName | FirstName | Address | City |
---|---|---|---|
Hansen | Ola | Timoteivn 10 | Sandnes |
Svendson | Tove | Borgvn 23 | Sandnes |
Pettersen | Kari | Storgt 20 | Stavanger |
The table above contains three records (one for each person) and four columns (LastName, FirstName, Address, and City).
SQL Queries
SQL查询
With SQL, we can query a database and have a result set returned.
利用SQL我们可以通过查询语句来对已有数据进行筛选并找到我们所需要的准确结果
A query like this:
这就是一句查询语句
SELECT LastName FROM Persons |
Gives a result set like this:
参照上面的数据表,返回的结果就因该是:
LastName |
---|
Hansen |
Svendson |
Pettersen |
Note: Some database systems require a semicolon at the end of the SQL statement. We don't use the semicolon in our tutorials.
注意:一些数据库系统需要在每条SQL语句结束后带上分号。在我们的教程中将不使用到分号。
SQL Data Manipulation Language (DML)
SQL 数据处理语言(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.
SQL是一种针对执行查询的语法。但SQL里还包括对记录进行更新,插入以及删除的语法。
These query and update commands together form the Data Manipulation Language (DML) part of SQL:
这些查询以及更新命令构成了SQL(DML)的一部分:
- 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)
SQL 数据定义语言(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.
数据定义语言(DDL)为SQL中的一部分,可以让数据表建立或是删除。我们还可以定义索引(键),指定表与表的连通,还可以加以限制。
The most important DDL statements in SQL are:
下面是在SQL中非常重要的DDL声明:
- 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
删除索引