mysql数据库基础增删改查

开启,与登录

net start mysql
mysql -u root -p

数据库:查看,创建,使用,删除

show databases;
create database school;
use school;
drop database school;

表: 对行的 插入,删除,修改,查询(增删改查)

create table students
(
	id int not null auto_increment,
	name varchar(10) not null,
	age int not null,
	primary key (id)
)engine=InnoDB;
show tables;

insert into students(id,name,age)		//不写列明表示使用所有列
values(null,'aaa',10),(null,'aaa',10);


delete from students where id = 1;

update students 
set age = 11 where id = 2;

select * from students;			

修改表结构:(加列,减列,改列名,改列属性)

alter table students add column remarks varchar(30);
alter table students drop column remarks;
alter table students modify name varchar(20);
alter table students modify name int;		//error  Incorrect integer value: 'aaa' for column 'name' at row 1

//以下不常用:改表名,查看列,
alter table students rename to mystudents;
desc students;

删除整张表:

delete from students;	//只删除所有行,且可以回滚
truncate table students;//释放空间,无法回滚。重设计数种子
drop table students;	//表结构,触发器索引都删,

drop后,再 show tables;  没有students表。但保留  依赖该表的存储过程

delete 数据库操作语言  dml	事务提交才生效
truncate 和 drop 数据库定义语言  ddl  操作生效

对于有外键引用的表,不能用truncate。
且truncate的操作记录在日志中,不会激活触发器。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值