1. Relational database
A relational database is a database composed of multiple two-dimensional tables that can be connected to each other
Table of contents
4. DDL (Data Definition Language)-------operation database
5. DML (Data Manipulation Language)------operation table
Two, SQL language
1. Introduction to SQL
- English: Structured Query Language, referred to as SQL
- Structured Query Language , a programming language for manipulating relational databases
- Define a unified standard for operating all relational databases
- For the same requirement, each database operation method may have some differences, which are jokingly called "dialects"
2. SQL general syntax
- SQL statements can be written in a single line or in multiple lines, ending with a semicolon .
- The SQL statements of the MySQL database are not case-sensitive , and keywords are recommended to be capitalized.
- note
Single-line comment: --comment content or #comment content (MySQL specific)
Multi-line comment: /* comment content */
3. SQL classification
DDL (Data Definition Language) : Database definition language, used to define database objects; databases, tables , lists, etc.
DML (Data Manipulation Language) : Database operation language, used to add, delete, and modify data in database tables .
DQL (Data Query Language) : Database query language, used to query the records (data) in the database.
DCL (Data Control Language) : Database control language, used to define the access rights and security levels of the database and create users.
4.DDL (Data Definition Language)-------operation database
- Inquire
show databases;
- create database
create database 数据库名称;
- Create a database (judgment, create if it does not exist)
create database if not exists 数据库名称:
- delete database
drop database 数据库名称;
- Delete the database (judgment, delete if it exists)
drop databases if exists 数据库名称:
- View the currently used database
select database();
- Use the database (enter the database)
use 数据库名称;
5. DML (Data Manipulation Language) ------ operation table
- Query all table names under the current database
show tables;
- query table structure
desc 表名称;
- create table
create table 表名( 字段名1 数据类型1, 字段名2 数据类型2, ..... 字段名n 数据类型n );/*注意:最后一行末尾,不能加逗号*/
-
modify table name
alter table 表名 rename to 新表名;
-
Add a column in the table
alter table 表名 add 列名 数据类型;
- modify data type
alter table 表名 modify 列名 新数据类型;
- Modify column names and data types
alter table 表名 change 列名 新列名 新数据类型;
- delete column
alter table 表名 drop 列名;
-
delete table
drop table 表名;
-
Determining whether a table exists when deleting a table
drop table if exists 表名;
6. Data types in MySQL
MySQL supports a variety of data types, which can be divided into three categories:
- value
- date
- string
create table student(
id int,
name varchar(10),
gender char(1),
birthday date,
score double(5,2),
email varchar(64),
tel varchar(15),
status tinyint
);