SQL zero-based introductory learning (1)

Introduction to SQL

SQL (Structured Query Language: Structured Query Language) is used to manage relational database management systems (RDBMS). The scope of SQL includes data insertion, query, update, and deletion, database schema creation and modification, and data access control.

What is SQL?

SQL refers to Structured Query Language, and its full name is Structured Query Language.
SQL lets you access and manipulate databases, including data insertion, query, update, and delete.
SQL became an ANSI (American National Standards Institute) standard in 1986 and an International Organization for Standardization (ISO) standard in 1987.
What can SQL do?
SQL Executes queries against the database
SQL can retrieve data from the database
SQL can insert new records in the database
SQL can update data in the database
SQL can delete records from the database
SQL can create new databases
SQL can create new tables in the database
SQL can be used in Create stored procedures in the database
SQL can create views in the database
SQL can set the permissions of tables, stored procedures and views

SQL is a standard - but...

Although SQL is an ANSI (American National Standards Institute American National Standards Organization) standard computer language, there are still many different versions of the SQL language.
However, in order to be compatible with the ANSI standard, they must collectively support some major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE, etc.) in a similar manner.

lamp Note: In addition to the SQL standard, most SQL database programs have their own proprietary extensions!

Use SQL in your website

To create a website that displays data from a database, you need:

RDBMS database programs (like MS Access, SQL Server, MySQL)
use server-side scripting languages ​​like PHP or ASP
use SQL to get the data you want
use HTML/CSS

RDBMS

RDBMS refers to relational database management system, the full name is Relational Database Management System.

RDBMSs are the foundation of SQL, as well as of all modern database systems such as MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.

Data in an RDBMS is stored in database objects called tables.

A table is a collection of related data items, which consists of columns and rows.

SQL syntax

Database Table

A database usually contains one or more tables. Each table is identified by a name (for example: "Websites"), and the table contains records (rows) with data.

In this tutorial, we created the Websites table in MySQL's RUNOOB database to store website records.

We can view the data of the "Websites" table with the following command:

mysql> use RUNOOB;
Database changed

mysql> set names utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT * FROM Websites;
+----+--------------+---------------------------+-------+---------+
| id | name         | url                       | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1  | Google       | https://www.google.cm/    | 1     | USA     |
| 2  | 淘宝          | https://www.taobao.com/   | 13    | CN      |
| 3  | 菜鸟教程      | http://www.runoob.com/    | 4689  | CN      |
| 4  | 微博          | http://weibo.com/         | 20    | CN      |
| 5  | Facebook     | https://www.facebook.com/ | 3     | USA     |
+----+--------------+---------------------------+-------+---------+
5 rows in set (0.01 sec)

Parse
the use RUNOOB; command to select a database.
The set names utf8; command is used to set the character set used.
SELECT * FROM Websites; Read the information of the data table.
The above table contains five records (one for each website) and five columns (id, name, url, alexa, and country).

SQL statement

Most of the work you need to do on a database is done with SQL statements.

The following SQL statement selects all records from the "Websites" table:

example

SELECT * FROM Websites;

In this tutorial, we'll walk you through various SQL statements.

please remember…

SQL is not case sensitive: SELECT is the same as select.

Semicolon after SQL statement?

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

Semicolons are a standard way of separating each SQL statement in a database system so that more than one SQL statement can be executed in the same request to the server.

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

Some of the most important SQL commands

SELECT - extract data from the database
UPDATE - update data in the database
DELETE - delete data from the database
INSERT INTO - insert new data into the database
CREATE DATABASE - create a new database
ALTER DATABASE - modify the database
CREATE TABLE - create a new table
ALTER TABLE - ALTER (ALTER) DATABASE TABLE
DROP TABLE - drop table
CREATE INDEX - create index (search key)
DROP INDEX - drop index

Guess you like

Origin blog.csdn.net/weixin_44006731/article/details/129120408