Mysql简单联系

文章介绍了在数据库中创建英雄表,设置约束,插入80条角色数据,后续通过ALTER语句增加字段、删除字段并重命名表的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    1.创建数据库,创建英雄表
    2. 添加对应的约束条件
    3.插入80条数据
    4.通过alter添加两个新的字段
    5.通过alter删除一个字段
    6.重命名一张表

1.创建数据库

命令:create database   db_classic;

创建英雄表,添加对应约束条件

命令:create table t_hero(
        id int primary key auto_increment,
       nickname varchar(50) unique not null,
       age int  not null default 1000,
       address varchar(100) not null,
       job  char(30)   not null,
       weapon char(30) not null,
       graoup varchar(50) not null
    );

3.插入80数据

命令:insert into t_hero(nickname,age,address,job,weapon,graoup) values("猪八戒",1001,"高老庄","取经","九齿钉耙","四人帮");
 insert into t_hero(nickname,address,job,weapon,graoup) values("沙悟净","流沙河","取经","降妖宝杖","四人帮");
 insert into t_hero(nickname,address,job,weapon,graoup) values("唐僧","西土大唐","取经","九环锡杖","四人帮");
insert into t_hero(nickname,address,job,weapon,graoup) values("宋江","山东郓城","造反","大刀","108好汉");
insert into t_hero(nickname,address,job,weapon,graoup) values("卢俊义","河北大名府","造反","剑","108好汉");
insert into t_hero(nickname,address,job,weapon,graoup) values("花荣","清风寨","造反","银枪","108好汉");

............

4.增加两个列名

命令:

alter table  t_hero add family  varchar(30) not null;

alter table  t_hero add gender  varchar(30) not null;

5.删除一个字段列名;修改表名

命令:alter table t_hero drop family;

           rename table t_hero to t_heros;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值