最适合网络开发者的网站

SQL 教程

SQL主页 SQL 简介 SQL 语法 SQL 选择 SQL 选择不同 SQL 语句 SQL 排序依据 SQL 和 SQL 或 SQL不是 SQL 插入 SQL 空值 SQL 更新 SQL 删除 SQL 选择顶部 SQL 最小值和最大值 SQL 计数 SQL 汇总 SQL 平均值 SQL 类似 SQL 通配符 SQL 输入 SQL 之间 SQL 别名 SQL 连接 SQL 内连接 SQL左连接 SQL右连接 SQL全连接 SQL自连接 SQL联盟 SQL 分组依据 SQL 具有 SQL 存在 SQL 任何、全部 SQL 选择 SQL 插入选择 SQL 案例 SQL 空函数 SQL 存储过程 SQL 注释 SQL 运算符

SQL 数据库

SQL创建数据库 SQL删除数据库 SQL 备份数据库 SQL创建表 SQL删除表 SQL 修改表 SQL 约束 SQL 非空 SQL唯一标识符 SQL 主键 SQL 外键 SQL 检查 SQL 默认值 SQL 索引 SQL 自动增量 SQL 日期 SQL 视图 SQL 注入 SQL 托管 SQL 数据类型

SQL 参考

SQL 关键字 MySQL 函数 SQL Server 函数 MS Access 函数 SQL 快速参考

SQL 例子

SQL 示例 SQL 编辑器 SQL 测验 SQL 练习 SQL训练营 SQL 证书

SQL。初学者课程

尿素

SQL Syntax


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.

In this tutorial we will use the well-known Northwind sample database (included in MS Access and MS SQL Server).

Below is a selection from the "Customers" table:

CustomerID CustomerName ContactName Address City PostalCode Country
1

Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Germany
2 Ana Trujillo Emparedados y helados Ana Trujillo Avda. de la Constitución 2222 México D.F. 05021 Mexico
3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico
4

Around the Horn Thomas Hardy 120 Hanover Sq. London WA1 1DP UK
5 Berglunds snabbköp Christina Berglund Berguvsvägen 8 Luleå S-958 22 Sweden

The table above contains five records (one for each customer) and seven columns (CustomerID, CustomerName, ContactName, Address, City, PostalCode, and Country).


SQL Statements

Most of the actions you need to perform on a database are done with SQL statements.

The following SQL statement selects all the records in the "Customers" table:

Example

SELECT * FROM Customers;
Try it Yourself »

In this tutorial we will teach you all about the different SQL statements.


Keep in Mind That...

  • SQL keywords are NOT case sensitive: select is the same as SELECT

In this tutorial we will write all SQL keywords in upper-case.


Semicolon after SQL Statements?

Some database systems require a semicolon at the end of each SQL statement.

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.

In this tutorial, we will use semicolon at the end of each SQL statement.


Some of The Most Important SQL Commands

  • SELECT - extracts data from a database
  • UPDATE - updates data in a database
  • DELETE - deletes data from a database
  • INSERT INTO - inserts new data into a database
  • CREATE DATABASE - creates a new database
  • ALTER DATABASE - modifies a database
  • CREATE TABLE - creates a new table
  • ALTER TABLE - modifies a table
  • DROP TABLE - deletes a table
  • CREATE INDEX - creates an index (search key)
  • DROP INDEX - deletes an index