Get the App
SLTechnology News&Howtos  ›  Database  › 

[MySQL Learning Notes] 2. SQL statement

Shulou Source: shulou.com Published: 2022-06-01 18:21:03 09月28日 Update

I. SQL statement

SQL:Structured Query Language, a structured query language, is a language for conversations between clients and SQL servers, which is used to talk to SQL servers.

It belongs to the programming language of interpretation and execution, whose code file is usually called script and is directly executed by the interpreter.

Sample SQL script

The following SQL script contains two SQL statements

/ * enter the database * / USE EXAMPLE;SELECT * FROM student

Note:

1. Note: / * /

2. A semicolon should be added at the end of each SQL statement, with a line break in the middle.

3. Key words are recommended to be capitalized. Some servers may not be case-sensitive

II. Database operation

(if there are no special characters in the name, the ``symbol can be used)

Create a database: (CREATE)

CREATE DATABASE `aaa`

Delete database: (DROP)

DROP DATABASE `aaa`

Create a table:

The format is as follows:

CREATE TABLE `Table name` (field 1, field 2...PRIMARY KEY ('key field name'); / * the format of the field is: 'field name' type (length) whether null is allowed * /

Delete the table:

DROP TABLE `Table name`

Import (backup) and export (restore) of the database:

The exported content contains not only the structure of the table, but also the content data of the table.

The exported sql file is actually the SQL command.

Develop a database:

USE `example`

Add records (rows):

/ * Syntax format: INSERT INTO VALUSE*//* field name: `value: "" or''* / INSERT INTO `student` (`id`, `name`. `cellphont`) VALUES ('0001,' ZhangSan', '123'); (' 0002, 'LeeSi',' 345')

Query record:

Use * to indicate all columns, such as the following statement, to query the entire table:

SELECT * FROM `student`

The following statement means to view only the contents of the field `id`:

SELECT `id`FROM `student`

Tags: Field data database statement content server format script language service query name that is file structure dialogue interpretation special no code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MySQL Huawei OPPO Reno Apple