作业1-数据表管理操作-添加、修改、删除表记录

create database test;
use test;
create table teacher
(
    id       int(4) auto_increment comment '编号',
    num      int(10)     not null comment '教工号',
    name     varchar(20) not null comment '姓名',
    sex      varchar(4)  not null comment '性别',
    birthday datetime    null comment '出生日期',
    address  varchar(50) null comment '家庭住址',
    constraint teacher_pk
        primary key (id)
);
insert into teacher value ('1','1001','张三','男','1984-11-08','北京市昌平区');
insert into teacher value ('2','1002','李四','女','1970-01-21','北京市海淀区');
insert into teacher value (null,'1003','王五','男','1976-10-30','北京市昌平区');
insert into teacher value (null,'1004','赵六','男','1980-06-05','北京市顺义区');

update teacher
set birthday = '1982-11-08'
where id = 1;

update teacher
set address = '北京市朝阳区'
where sex = '男';

delete
from teacher
where num = 1002;
create table food
(
    id      int(10) auto_increment comment '编号'
        primary key,
    name    varchar(20) not null comment '食品名称',
    company varchar(30) not null comment '生产厂商',
    price   float       null comment '价格',
    product_time year comment '生产年份',
    validity_time int(4) comment '保质期',
    address varchar(50) comment '厂址'
);
insert into food value ('1','aa饼干','aa饼干厂','2.5','2018','3','北京');
insert into food value('2','cc牛奶','cc牛奶厂','3.5','2015','1','河北');
insert into food value(null,'ee果冻','ee果冻厂','1.5','2018','2','北京');
insert into food value('null','ff咖啡','ff咖啡厂','20','2016','5','天津');
insert into food value(null,'gg奶糖','gg奶糖','14','2014','3','广东');
update food
set address = '内蒙古'
where name = 'cc牛奶厂';
update food
set price  = '3.2'
where name = 'cc牛奶厂';
update food
set validity_time = '5'
where address = '北京';
delete from food where (2025-food.product_time )> food.validity_time;

delete from food where address = '北京';

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值