1. 程式人生 > >MySQL基本操作--庫表增刪改查

MySQL基本操作--庫表增刪改查

change har str ccf 行記錄 base clas 字符集 切換

  • 庫的增刪改查

: create database db1;

: drop database db1;

: alter database db1 charset utf8; 修改庫的字符集編碼

: show database; 查看所有的數據庫

show create database db1\G; 查看數據庫創建信息

  • 表的增刪改查

切換庫: use db1 #要操作表文件,要先切換到對應的庫下才能操作

: create table tb1(id int);

: drop table tablename;

(表字段的修改,表結構的修改):

Alter table xx rename xxx

Alter table xx modify 字段名 數據類型 完整約束

Change 舊字段名 新字段名 數據類型 完整性約束

Alter table xx add 字段名 數據類型 完整約束 first;

After 字段名

Alter table xx add foreign key(c_id) references class(id);

: show tables;

  • 行記錄操作

增: INSERT INTO 表名(字段1,字段2,字段3…字段n) VALUES(值1,值2,值3…值n)

MySQL基本操作--庫\表增刪改查