Operate the database
1. DDL: The database definition language operates on the database and table structure to build a database, build a table, modify the table structure, delete a database, delete a table, etc.
(SQL statements are not case sensitive)
1. Create a database
CREATE DATABASE [IF NOT EXISTS] dbname [charset=utf8 collate utf8_general_ci];
create database student;
2. Show all databases
SHOW DATABASES;
3. Switch to the database to be used, USE database name;
4.4. Delete the database!
DROP DATABASE [IF EXISTS] 数据库名;
drop database student;
5. Build a table
5.建表
CREATE TABLE [IF NOT EXISTS] tablename(字段名 字段类型,....)[charset=utf8];
create table if not exists student(id integer,name varchar(20),age integer);
charset=utf8;
6. Display all tables in the current database
SHOW TABLES;
7. Display the table building statement
SHOW CREATE TABLE 表名;
show create table student;
8. Add a column to the table
ALTER TABLE 表名 ADD 字段名 字段类型;
ALTER TABLE 表名 ADD (字段名 字段类型,...)
alter table student add sex varchar(5);
9. Modify the column definition
ALTER TABLE 表名 MODIFY 字段名 新字段类型;
alter table student modify sex text;
ALTER TABLE 表名 CHANGE 旧列名 新列名 新列定义;
alter table student change sex 性别 varchar(5);
modify无法修改列名,change可以修改列名
10.Delete columns
ALTER TABLE 表名 DROP 列名;
alter table student drop 性别;
11. Delete table
DROP TABLE [IF EXISTS] 表名;
drop table student;