当前位置: 首页 > 网络学院 > 服务端脚本教程 > SQL > SQL 介绍
SQL is a standard computer language for accessing and manipulating databases.
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!
注意:大多数数据库程序都带有属于他们自身特色的扩展属性。
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).
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 (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)的一部分:
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声明: