1. What is sql statement
Structured Query Language (SQL) is abbreviated as SQL. Structured Query Language is a database query and programming language used to access data and query, update and manage relational database systems;
SQL statement is a language for operating on the database.
2. The sql language is divided into 3 types according to its functions:
1.
DDL statement database definition language: database, table, view, index, stored procedure, such as CREATE DROP ALTER
2.
DML statement database manipulation language: insert data INSERT, delete data DELETE, update data UPDATE, query data SELECT
3.
DCL statement database control language: For example, control user's access authority GRANT, REVOKE
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1. Folder (library) 增:create database db1 charset utf8; 改:alter database db1 charset gbk; check: View library names of all libraries show databases; View information about a library alone show create database db1; 删:drop database db1; 2. Documents (tables) First switch folders: use db1; select database(); #View the current folder Add create table t1(id int,name char); change alter table t1 modify name char(16); check View all table names under the current library show tables; View details of t1 table show create table t1; View table structure desc t1; delete drop table t1; 3. A line of content of the file (record) increase insert into db1.t1 values ( 1, ' fixd ' ), ( 2, ' lius ' ) ( 3, ' maef ' ); change update db1.t1 set name='sb' where id > 1; check select id,name from db1.t1; delete delete from db1.t1 where name = "SB" ;
3. Library operation
1. Create a database
CREATE DATABASE database name charset utf8;
Note: (database naming rules)
Can be composed of letters, numbers, underscores, @, #, $
case sensitive
uniqueness
Cannot use keywords such as create select
Numbers cannot be used alone
Up to 128 bits
2. Database operation
View all library names
show databases;
view the information of a database alone
show create database db1;
view the current database
select database();
select database
USE database name
delete database
DROP DATABASE database name;
Modify the database ( the main modification is the character encoding of the library, and the name of the library cannot be modified. )
alter database db1 charset utf8;