Sql 简明教程
SQL Tutorial
SQL Tutorial
我们的 SQL tutorial 帮助您以简单易懂的步骤学习 SQL(结构化查询语言),以便您可以快速开始数据库编程。它涵盖了与 SQL 相关的大部分重要概念,从对 SQL 的基本到高级理解,并了解 SQL 的工作原理。
Our SQL tutorial helps you learn SQL (Structured Query Language) in simple and easy steps so that you can start your database programming quickly. It covers most of the important concepts related to SQL for a basic to advanced understanding of SQL and to get a feel of how SQL works.
SQL(结构化查询语言)是一种编程语言,用于管理存储在关系数据库(如 MySQL、MS Access、SQL Server、Oracle、Sybase、Informix、Postgres 等)中的数据。
SQL (Structured Query Language) is a programming language which is used to manage data stored in relational databases like MySQL, MS Access, SQL Server, Oracle, Sybase, Informix, Postgres etc.
SQL 是一种数据库计算机语言,专为在关系数据库(如 MySQL、MS Access、SQL Server、Oracle、Sybase、Informix、Postgres 等)中检索和管理数据而设计。 SQL 代表 Structured Query Language 。SQL 是由 IBM 计算机科学家在 20 世纪 70 年代开发的。
SQL is a database computer language designed for the retrieval and management of data in a relational databases like MySQL, MS Access, SQL Server, Oracle, Sybase, Informix, Postgres etc. SQL stands for Structured Query Language. SQL was developed in the 1970s by IBM Computer Scientists.
SQL Examples
考虑我们有以下 CUSTOMERS 表,用于存储客户的 ID、姓名、年龄、工资、城市和国家/地区:
Consider we have following CUSTOMERS table which stores customer’s ID, Name, Age, Salary, City and Country −
ID |
Name |
Age |
Salary |
City |
Country |
1 |
Ramesh |
32 |
2000.00 |
Maryland |
USA |
2 |
Mukesh |
40 |
5000.00 |
New York |
USA |
3 |
Sumit |
45 |
4500.00 |
Muscat |
Oman |
4 |
Kaushik |
25 |
2500.00 |
Kolkata |
India |
5 |
Hardik |
29 |
3500.00 |
Bhopal |
India |
6 |
Komal |
38 |
3500.00 |
Saharanpur |
India |
7 |
Ayush |
25 |
3500.00 |
Delhi |
India |
SQL 使得使用简单的 DML(数据操作语言)语句操作此数据变得很容易。例如,如果我们想要列出来自美国的客户,那么以下将是 SQL 查询。
SQL makes it easy to manipulate this data using simple DML (Data Manipulation Language) Statements. For example, if we want to list down all the customers from USA then following will be the SQL query.
SELECT * FROM CUSTOMERS WHERE country = 'USA';
这将产生以下结果:
This will produce the following result:
ID |
Name |
Age |
Salary |
City |
Country |
1 |
Ramesh |
32 |
2000.00 |
Maryland |
USA |
2 |
Mukesh |
40 |
5000.00 |
New York |
USA |
SQL Online Editor
我们提供了 SQL Online Editor ,它可以帮助您直接从浏览器 Edit 和 Execute SQL 代码。尝试单击图标以运行以下 SQL 代码,以便在 CUSTOMERS 表上执行并打印与给定条件匹配的记录。
We have provided SQL Online Editor which helps you to Edit and Execute the SQL code directly from your browser. Try to click the icon to run the following SQL code to be executed on CUSTOMERS table and print the records matching with the given condition.
SELECT * FROM CUSTOMERS WHERE country = 'USA';
所以现在,您无需进行复杂的设置来执行本教程中给出的所有示例,因为我们为您提供 Online SQL Editor ,允许您编辑代码并在网上进行编译。您可以尝试我们的 Online SQL Editor 。
So now, you do not need to do a sophisticated setup to execute all the examples given in this tutorial because we are providing you Online SQL Editor, which allows you to edit your code and compile it online. You can try our Online SQL Editor.
SQL Basic Commands
我们有一系列标准 SQL 命令来与关系数据库进行交互,这些命令是 CREATE、SELECT、INSERT、UPDATE、DELETE、DROP 和 TRUNCATE,并且可以根据它们的性质分为以下组:
We have a list of standard SQL commands to interact with relational databases, These commands are CREATE, SELECT, INSERT, UPDATE, DELETE, DROP and TRUNCATE and can be classified into the following groups based on their nature −
Data Definition Language (DDL)
数据定义语言 (DDL) 是一种计算机语言,用于创建和修改数据库对象的结构,这些对象包括表、视图、架构和索引等。
A Data Definition Language (DDL) is a computer language which is used to create and modify the structure of database objects which include tables, views, schemas, and indexes etc.
Command |
Description |
Demo |
CREATE |
Creates a new table, a view of a table, or other object in the database. |
|
ALTER |
Modifies an existing database object, such as a table. |
|
DROP |
Deletes an entire table, a view of a table or other objects in the database. |
|
TRUNCATE |
Truncates the entire table in a go. |
Demo |
Data Manipulation Language (DML)
数据操作语言 (DML) 是一种计算机编程语言,用于增加、删除和修改数据库中的数据。
A Data Manipulation Language (DML) is a computer programming language which is used for adding, deleting, and modifying data in a database.
Command |
Description |
Demo |
SELECT |
Retrieves certain records from one or more tables. |
|
INSERT |
Creates a record. |
|
UPDATE |
Modifies records. |
|
DELETE |
Deletes records. |
Data Control Language (DCL)
数据控制语言 (DCL) 是一种计算机编程语言,用于控制对存储在数据库中的数据的访问。
Data Control Language (DCL) is a computer programming language which is used to control access to data stored in a database.
Command |
Description |
Demo |
GRANT |
Gives a privilege to user |
Demo |
REVOKE |
Takes back privileges granted from user. |
Demo |
Why to Learn SQL?
SQL(结构化查询语言)是学生和职业人士成为优秀软件工程师的必需品,特别是在他们从事软件开发领域时。SQL 是最常用的语言,几乎在每个应用程序软件中都使用,包括银行、金融、教育、安全等,用于存储和操作数据。
SQL (Structured Query Language) is a MUST for the students and working professionals to become a great Software Engineer specially when they are working in Software Development Domain. SQL is the most common language used almost in every application software including banking, finance, education, security etc. to store and manipulate data.
SQL 相当容易学习,因此如果您开始学习任何编程语言,那么强烈建议您还要学习 SQL 和其他与数据库相关概念,以成为一名全面的软件程序员。有许多充分的理由使 SQL 成为任何程序员的首选:
SQL is fairly easy to learn, so if you are starting to learn any programming language then it is very much advised that you should also learn SQL and other Database related concepts to become a complete Software Programmer. There are many good reasons which makes SQL as the first choice of any programmer −
SQL 是任何关系数据库系统的标准语言。所有关系数据库管理系统 (RDBMS),如 MySQL、MS Access、Oracle、Sybase、Informix、Postgres 和 SQL Server 都将 SQL 作为其标准数据库语言。
SQL is the standard language for any Relational Database System. All the Relational Data Base Management Systems (RDBMS) like MySQL, MS Access, Oracle, Sybase, Informix, Postgres and SQL Server use SQL as their standard database language.
此外,软件行业正在使用不同的 SQL 方言,例如:
Also, software industry is using different dialects of SQL, such as −
-
MS SQL Server using T-SQL,
-
Oracle using PL/SQL,
-
MS Access version of SQL is called JET SQL (native format) etc.
SQL Applications
SQL 是在数据库上使用最广泛的查询语言之一。SQL 为数据库程序员提供以下功能:
SQL is one of the most widely used Query Language over the databases. SQL provides following functionality to the database programmers −
-
Execute different database queries against a database.
-
Define the data in a database and manipulate that data.
-
Create data in a relational database management system.
-
Access data from the relational database management system.
-
Create and drop databases and tables.
-
Create and maintain database users.
-
Create view, stored procedure, functions in a database.
-
Set permissions on tables, procedures and views.
Who Should Learn SQL
本 SQL tutorial 对学生和希望为某些数据库(如银行系统、支持系统、信息系统、网站、移动应用或个人博客等)开发应用程序的职业人士有所帮助。我们建议按照左侧菜单中列出的顺序阅读本教程。
This SQL tutorial will help both students as well as working professionals who want to develop applications based on some databases like banking systems, support systems, information systems, web websites, mobile apps or personal blogs etc. We recommend reading this tutorial, in the sequence listed in the left side menu.
如今,对于软件应用程序开发过程中涉及的任何人(包括软件开发人员、软件设计师和项目经理等)而言,SQL 都是一门必学语言。
Today, SQL is an essential language to learn for anyone involved in the software applicatipon development process including Software Developers, Software Designers, and Project Managers etc.
Prerequisites to Learn SQL
尽管我们已尽力用简单易懂的方式介绍 SQL 概念,但在你开始学习本教程中给出的 SQL 概念之前,我们假设你已了解一些计算机科学基本概念、数据库是什么(尤其是 RDBMS 基础)及相关概念。
Though we have tried our best to present the SQL concepts in a simple and easy way, still before you start learning SQL concepts given in this tutorial, it is assumed that you are already aware about some basic concepts of computer science, what is a database, especially the basics of RDBMS and associated concepts.
本教程将为你提供足够的 SQL 概念理解,同时提供合适的示例,让你能够在完成本教程后立即开启你的软件开发之旅。
This tutorial will give you enough understanding on the various concepts of SQL along with suitable examples so that you can start your Software Development journey immediately after finishing this tutorial.
SQL Online Quizzes
本 SQL 教程可以帮助你为技术面试和认证考试做好准备。我们提供了多种测验和作业来检查你的学习水平。提供的测验包括多项选择题以及其答案和简短说明。
This SQL tutorial helps you prepare for technical interviews and certification exams. We have provided various quizzes and assignments to check your learning level. Given quizzes have multiple choice type of questions and their answers with short explanation.
以下是样本测验,请尝试回答任何给定的答案:
Following is a sample quiz, try to attempt any of the given answers:
开始你的在线测验 Start SQL Quiz 。
Start your online quiz Start SQL Quiz.
SQL Jobs and Opportunities
随着数据呈指数级增长,SQL 专业人士的需求量很大。几乎每一家大公司都在招募具有良好 SQL 经验的 IT 专业人士。
SQL professionals are very much in high demand as the data turn out is increasing exponentially. Almost every major company is recruiting IT professionals having good experience with SQL.
SQL 专业人士的平均年薪约为 150,000 美元。但这可能因地域而异。以下是始终招募 SQL 专业人士的优秀公司,如数据库管理员 (DBA)、数据库开发人员、数据库测试人员、数据科学家、ETL 开发人员、数据库迁移专家、云数据库专家等:
Average annual salary for a SQL professional is around $150,000. Though it can vary depending on the location. Following are the great companies who keep recruiting SQL professionals like Database Administrator (DBA), Database Developer, Database Testers, Data Scientist, ETL Developer, Database Migration Expert, Cloud Database Expert etc:
-
Google
-
Amazon
-
Netflix
-
Infosys
-
TCS
-
Tech Mahindra
-
Wipro
-
Pinterest
-
Uber
-
Trello
-
Many more…
因此,你可以成为其中任何一家大公司的下一个潜在员工。我们为 SQL 开发了极好的学习资料,这将帮助你准备基于 SQL 的技术面试和认证考试。因此,随时随地,按照自己的节奏使用我们的简单有效的教程开始学习 SQL。
So, you could be the next potential employee for any of these major companies. We have developed a great learning material for SQL which will help you prepare for the technical interviews and certification exams based on SQL. So, start learning SQL using our simple and effective tutorial anywhere and anytime absolutely at your pace.