Mysql 的 增删改查

mysql的增删改查

1:新建数据库

create database 数据库名 [其他选项];

2:新建数据表

create table students
(
id int unsigned not null auto_increment primary key,
name char(8) not null,
sex char(4) not null,
age tinyint unsigned not null,
tel char(13) null default "-"
);

3:写入数据[数据表]

insert into students values(id, "name", "sex", age, "tel");

4:删除数据[数据表]

delete from 表名称 where 删除条件;

5:修改/更新数据[数据表]

update 表名称 set 列名称=新值 where 更新条件;

6:查询数据[数据表]

select 列名称 from 表名称 [查询条件];

7:创建表后,如何进行修改数据表

alter table 语句用于创建后对表的修改, 基础用法如下:
alter table 表名 add 列名 列数据类型 [after 插入位置];
在表的最后追加列 address: alter table students add address char(60);
在名为 age 的列后插入列 birthday: alter table students add birthday date after age;

8:修改数据表中的列

修改列
基本形式: alter table 表名 change 列名称 列新名称 新数据类型;
将 name 列的数据类型改为 char(16): alter table students change name name char(16) not null;

9:删除数据表中的列

删除列
alter table 表名 drop 列名称;
删除 birthday 列: alter table students drop birthday;

10:重命名数据表中的列

重命名列
基本形式: alter table 表名 rename 新表名;
重命名 students 表为 workmates: alter table students rename workmates;

11:删除整张数据表

删除整张表
基本形式: drop table 表名;
示例: 删除 workmates 表: drop table workmates;

12:删除整个数据库

删除整个数据库
基本形式: drop database 数据库名;
示例: 删除 samp_db 数据库: drop database samp_db;

参考:https://www.cnblogs.com/webnote/p/5753996.html

猜你喜欢

转载自www.cnblogs.com/willamwang/p/11038775.html