MySQL 增删改查

时间:2023-03-08 23:44:43
MySQL 增删改查

增--添加数据

新建数据库
create database newdatabase;

选择数据库
use newdatabase;

新建表
create table newtable(id int,name varchar(20),age int);

给表添加数据
insert into newtable(id,name,age) values(1,'zhangsan',18);
第二种写法:
insert into newtable set id=3,name='lisi',age=30;
添加多条数据:
insert into newtable values(2,'aa',12),(3,'bb',13);

删--删除数据

删除数据库
drop database newdatabase;

删除表
drop table newtable;

快速删除表
truncate newtable;

删除全部数据
delete * from newtable;

删除列
alter table 表名 drop column 列名;

改--更新数据