MySql 自习

create database pangya;//建数据库pangya

use pangya;//使用数据库pangya

create table shapang(
sid int not null primary key auto_increment,
sname varchar(20) not null,
ssex varchar(5) not null check (ssex in ('男','女')),
sage int not null check(sage between 0 and 150),
stel varchar(11) unique
);//建表shapang

insert into shapang(sname,ssex,sage,stel) value(
'pangya',
'女',
20,
'15099061981'
);//插入一条数据

select  *  from shapang;//查询数据

select * from shapang where sname like'_a%';//模糊查询

alter table shapang drop stel;//删除shapang表中的stel字段

alter table shapang add stel varchar(11);//增加shapang表中的stel字段

alter table shapang modify stel varchar(13);//将stel字段的长度由11改为13(关键字为modify)

delete from shapang where sage=151;//删除shapang表中年龄为151的数据

提取系统当前日期:
select curdate();
提取系统当前年份:
select extract(year from curdate());
提取员工入职年份(在scott表下操作):
select extract(year from hiredate);
获取员工的工作年限(在scott表下操作):
select extract(year from curdate())-extract(year from hiredate) from emp;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值