数据库

数据库

1、登陆数据库

mysql -uroot -p123456 --prompt="\u@\h:\d--> "

2、创建数据库zoo

create database zoo;

3、修改数据库zoo字符集为gbk

alter database zoo default character set gbk collate gbk_chinese_ci;

4、选择当前数据库为zoo

use zoo

5、查看创建数据库zoo信息

show tables from zoo;

6、删除数据库zoo

drop database zoo;

二、创建表
1、创建一个名称为db_system的数据库

create database db_system;

2、在该数据库下创建两张表,具体要求如下
员工表 user

字段类型约束备注
id整形主键自增长 id
NAME字符型非空姓名
gender字符非空性别
birthday日期型生日
entry_date日期型非空入职时间
job字符型非空职位
create table user(
id int primary key auto_increment comment 'id',
name char(20) not null comment '姓名',
gender char(4) not null comment '性别',
birthday date comment '生日',
entry_date date not null comment '入职时间',
job char(30) not null comment '职位');

员工绩效表 salary

字段类型约束备注
id整形主键自增长 id
userId字符型非空,外键关联的是user表的id字段 用户id
baseSalary小数非空基本工资
month整数非空月份
allowances小数非空默认为0 补贴
create table salary(
id int primary key auto_increment comment 'id',
userid int not null comment '用户id',
baseSalary double not null comment '基本工资',
month int not null comment '月份',
allowances double not null default'0.0' comment '补贴');
alter table salary add constraint fk_userid
foreign key(userid) references user(id);

三、修改表
1、在上面员工表的基本上增加一个image列,类型是blod,长度255。

alter table user add image blob(255) ;

2、修改job列,使其长度为60。

alter table user modify job char(60);

3、删除gender列。

alter table user drop gender;

4、表名salary改为usersalary。

alter table salary rename usersalary ;

5、修改表的字符集为utf8;

alter table user default character set utf8 collate utf8_unicode_ci;

6、列名name修改为username

alter table user change name username char(20);
  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值