【mysql基础】mysql 四种类型语句常见操作-一. DDL (Data Definition Language)

1. 创建数据库和表

创建库(CREATE DATABASE)

CREATE DATABASE database_name

## 进入库(USE)

USE database_name

## 查看表(SHOW)

SHOW TABLES;
SHOW TABLES FROM database_name;


## 创建表(CREATE TABLE)

`CREATE TABLE table_name (column1_name INT, column2_name VARCHAR(50), column3_name VARCHAR(50));`

 

2. 修改列(ALTER TABLE)


### 修改列(CHANGE COLUMN)

ALTER TABLE table_name CHANGE COLUMN old_col_name new_col_name INT AUTO_INCREMENT PRIMARY KEY


mysql> ALTER TABLE students
    -> CHANGE COLUMN id id INT AUTO_INCREMENT PRIMARY KEY;



### 增加列(ADD COLUMN)

ALTER TABLE table_name ADD COLUMN new_col1_name TEXT , ADD COLUMN new_col2_name VARCHAR(255);



### 删除列 DROP

ALTER TABLE table_name DROP COLUMN col1_name, DROP COLUMN col2_name

mysql> ALTER TABLE students
    -> DROP COLUMN age;

 

3. 删除库表

DROP TABLE table_name;


# 慎用
DROP DATABASE database_name;

 

上一篇:ShuffleNet模型详解


下一篇:网络——套接字编程UDP