Mysql——创建数据库,对表的创建及字段定义、数据录入、字段增加及删除、重命名表。

本文主要是介绍Mysql——创建数据库,对表的创建及字段定义、数据录入、字段增加及删除、重命名表。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一.创建数据库

create database db_classics default charset=utf8mb4;//创建数据库
use db_classics;//使用该数据库

二.对表的创建及字段定义

create table if not exists t_hero (
id int primary key auto_increment,
Name varchar(100) not null unique,
Nickname varchar(100) not null unique,
Age int not null unique,
Address text not null unique,
club varchar(100) not null unique,
weapon varchar(100) not null unique,
bloc varchar(100) not null unique
);

 三.数据录入

insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(1,“孙悟空”,”齐天大圣”,600,”花果山水帘洞”,”取经大队”,”金箍棒”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(2,“唐僧”,”金蝉子”,30,”东土大唐”,”取经大队”,”禅杖”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(3,“猪八戒”,”天蓬元帅”,800,”高老庄”,”取经大队”,”九齿钉耙”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(4,“沙悟净”,”卷帘大将”,700,”流沙河”,”取经大队”,”降妖宝杖”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(5,“玉帝”,”玉皇大帝”,30000,”天庭”,”神界”,”开天斧”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(6,“白龙马”,”龙王三太子”,500,”西海龙宫”,”取经大队”,”龙泉宝剑”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(7,“如来佛祖”,”释迦牟尼尊者”,99999,”西天灵山”,”佛教”,”舍利子”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(8,“观影菩萨”,”观世音菩萨”,10000,”南海普陀落伽山潮音洞”,”佛教”,”玉净瓶”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(9,“黑熊怪”,”黑风怪”,500,”黑风洞”,”妖怪”,”黑缨枪”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(10,“红孩儿”,”圣婴大王”,400,”钻头号山”,”妖界”,”火尖枪”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(11,“牛魔王”,”大力牛魔王”,2000,”翠云山芭蕉洞”,”妖界”,”混铁棍”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(12,“铁扇公主”,”罗莎女”,1800,”翠云山芭蕉洞”,”妖界”,”芭蕉扇”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(13,“镇元子”,”镇元大仙”,20000,”五庄观”,”神界”,”拂尘”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(14,“菩提老祖”,”须菩提祖师”,20000,”灵台方寸山斜月三星洞”,”神界”,”拂尘”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(15,“白骨精”,”白骨夫人”,1000,”白虎岭”,”妖界”,”白骨剑”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(16,“金角大王”,”大大王”,800,”平顶山莲花洞”,”妖界”,”紫金红葫芦”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(17,“银角大王”,”二大王”,700,”平顶山莲花洞”,”妖界”,”羊脂玉净瓶”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(18,“哪吒”,”哪吒三太子”,800,”天庭”,”神界”,”风火轮”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(19,“杨戬”,”二郎神”,2000,”天庭”,”神界”,”三尖双刃刀”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(20,“太上老君”,”太上祖道”,20000,”天庭”,”神界”,”拂尘”,”西游记”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(21,“刘备”,”刘玄德”,40,” 涿郡涿县”,”蜀国”,”双股剑”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(22,“关羽”,”关云长”,35,”河东郡解良县”,”蜀国”,”青龙偃月刀”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(23,“张飞”,”张益德”,32,”涿郡”,”蜀国”,”丈八蛇矛”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(24,“诸葛亮”,”诸葛孔明”,27,”徐州琅琊阳都”,”蜀国”,””,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(25,“赵云”,”赵子龙”,29,”常山真定”,”蜀国”,”涯角枪”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(26,“黄忠”,”黄汉升”,50,”南阳”,”蜀国”,”凤嘴刀”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(27,“马超”,”马孟起”,30,”扶风茂陵”,”蜀国”,”马骑枪”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(28,“曹操”,”曹孟德”,46,”沛国谯县”,”魏国”,”倚天剑和青釭剑”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(29,“庞统”,”庞士元”,29,”襄阳”,”蜀国”,””,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(30,“夏侯惇”,”夏元让”,35,” 沛国谯县”,”魏国”,”长枪”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(31,“司马懿”,”司仲达”,29,”河内温县”,”魏国”,””,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(32,“典韦”,”古之恶来”,30,”陈留己吾”,”魏国”,”大双戟”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(33,“孙坚”,”孙文台”,40,”吴郡富春”,”吴国”,”长剑”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(34,“孙策”,”孙伯符”,20,”吴郡富春”,”吴国”,”长剑”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(35,“孙权”,”孙仲谋”,13,”吴郡富春”,”吴国”,”双剑”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(36,“黄盖”,”黄公覆”,29,”零陵郡泉陵”,”吴国”,”大双戟”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(37,“周瑜”,”周公瑾”,28,”庐江郡舒”,”吴国”,””,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(38,“吕蒙”,”吕子明”,32,”汝南富陂”,”吴国”,”长枪”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(39,“吕布”,”吕奉先”,33,”五原九元”,”魏国”,”方天画戟”,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(40,“徐庶”,”徐元直”,37,”颍川郡长社”,”蜀国”,””,”三国演义”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(41,“光头强”,”强哥”,32,”狗熊零”,”伐木组”,”电锯”,”熊出没”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(42,“凯”,”曙光凯”,37,”四川”,”长城守卫”,”曙光刀”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(43,“花木兰”,”巾帼英雄”,29,”四川”,”长城守卫”,”木兰刀”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(44,“苏烈”,”苏大强”,37,”四川”,”长城守卫”,”大柱”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(45,“百里守约”,”狙击手”,26,”陕西”,”长城守卫”,”狙击枪”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(46,“百里玄策”,”暗影勾手”,28,”陕西”,”长城守卫”,”暗影镰刀”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(47,“李白”,”青年居士”,28,”四川”,”长安”,”大河之剑”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(48,“盾山”,”铁石头”,56,”四川”,”长城守卫”,”坚固之盾”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(49,“李信”,”光暗信”,35,”湖南”,”长城守卫”,”长剑”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(50,“沈梦溪”,”炸弹人”,22,”湖北”,”长城守卫”,”投掷炸弹”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(51,“伽罗”,”长空射手”,26,”重庆”,”长城守卫”,”长空之弓”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(52,“兰陵王”,”暗影刺客”,37,”新疆”,”长城守卫”,”匕首”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(53,“明世隐”,”万能医疗箱”,35,”新疆”,”尧天”,”明镜”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(54,“裴擒虎”,”猛虎勇士”,29,””,”尧天”,”虎爪”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(55,“公孙离”,”盛世舞姬”,26,”新疆”,”尧天”,”雨伞”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(56,“杨玉环”,”杨贵妃”,35,”新疆”,”尧天”,”琵琶”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(57,“弈星”,”天元之弈”,28,”陕西”,”尧天”,”棋盘”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(58,“盘古”,”元始天王”,100000000,”四川”,”日之塔”,”开天斧”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(59,“女娲”,”创世女神”,100000000,”新疆”,”日之塔”,”混沌无极刀”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(60,“后裔”,”逐日者”,80000000,”新疆”,”日之塔”,”逐日之弓”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(61,“太乙真人”,”清微教主”,6000000,”陕西”,”日之塔”,”炼金瓶”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(62,“姜子牙”,”姜太公”,75,”陕西”,”日之塔”,”封神榜”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(63,“曜”,”东方曜”,2000,”北京”,”稷下星之队”,”光剑”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(64,“李元芳”,”水生”,30,”北京”,”长安”,”飞轮”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(65,“狄仁杰”,”断案大师”,46,”北京”,”长安”,”亢龙锏”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(66,“上官婉儿”,”上官昭容”,30,”陕西”,”长安”,”毛笔”,”王者荣耀”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(67,“宋江”,”及时雨”,42,”陕西”,”梁山好汉”,”长剑”,”水浒传”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(68,“晁盖”,”托塔天王”,40,”陕西”,”梁山好汉”,”长剑”,”水浒传”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(69,“卢俊义”,”玉麒麟”,38,”陕西”,”梁山好汉”,”长枪”,”水浒传”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(70,“林冲”,”豹子头”,40,”陕西”,”梁山好汉”,”长枪”,”水浒传”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(71,“李逵”,”黑旋风”,40,”四川”,”梁山好汉”,”双斧”,”水浒传”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(72,“鲁智深”,”花和尚”,36,”四川”,”梁山好汉”,”禅杖”,”水浒传”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(73,“武松”,”行者”,38,”重庆”,”梁山好汉”,”双刀”,”水浒传”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(74,“杨志”,”青面兽”,35,”重庆”,”梁山好汉”,”长枪”,”水浒传”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(75,“吴用”,”智多星”,39,”重庆”,”梁山好汉”,”长剑”,”水浒传”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(76,“土行孙”,”遁地者”,30,”陕西”,”伐纣队伍”,”捆仙绳”,”封神榜”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(77,“姬发”,”周武王”,21,”重庆”,”伐纣队伍”,”长剑”,”封神榜”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(78,“邓婵玉”,”六合星君”,26,”陕西”,”伐纣队伍”,”双刀”,”封神榜”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(79,“闻仲”,”闻太师”,55,”湖北”,”纣王队伍”,”雌雄蛟龙双鞭”,”封神榜”);
insert into t_hero(id, Name, Nickname, Age, Address,job,weapon,bloc) values(80,“纣王”,”子受”,40,”陕西”,”纣王队伍”,”长剑”,”水浒传”);

 四.字段增加及删除

增加字段
Alter table t_hero add gender enum('男', '女') default '女';
Alter table t_hero add classes varchar(100);删除字段
Alter table t_hero drop classes;

五.重命名表 

alter table t_hero rename hero;

这篇关于Mysql——创建数据库,对表的创建及字段定义、数据录入、字段增加及删除、重命名表。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/163106

相关文章

如何通过try-catch判断数据库唯一键字段是否重复

《如何通过try-catch判断数据库唯一键字段是否重复》在MyBatis+MySQL中,通过try-catch捕获唯一约束异常可避免重复数据查询,优点是减少数据库交互、提升并发安全,缺点是异常处理开... 目录1、原理2、怎么理解“异常走的是数据库错误路径,开销比普通逻辑分支稍高”?1. 普通逻辑分支 v

MySQL中On duplicate key update的实现示例

《MySQL中Onduplicatekeyupdate的实现示例》ONDUPLICATEKEYUPDATE是一种MySQL的语法,它在插入新数据时,如果遇到唯一键冲突,则会执行更新操作,而不是抛... 目录1/ ON DUPLICATE KEY UPDATE的简介2/ ON DUPLICATE KEY UP

MySQL分库分表的实践示例

《MySQL分库分表的实践示例》MySQL分库分表适用于数据量大或并发压力高的场景,核心技术包括水平/垂直分片和分库,需应对分布式事务、跨库查询等挑战,通过中间件和解决方案实现,最佳实践为合理策略、备... 目录一、分库分表的触发条件1.1 数据量阈值1.2 并发压力二、分库分表的核心技术模块2.1 水平分

Python与MySQL实现数据库实时同步的详细步骤

《Python与MySQL实现数据库实时同步的详细步骤》在日常开发中,数据同步是一项常见的需求,本篇文章将使用Python和MySQL来实现数据库实时同步,我们将围绕数据变更捕获、数据处理和数据写入这... 目录前言摘要概述:数据同步方案1. 基本思路2. mysql Binlog 简介实现步骤与代码示例1

使用shardingsphere实现mysql数据库分片方式

《使用shardingsphere实现mysql数据库分片方式》本文介绍如何使用ShardingSphere-JDBC在SpringBoot中实现MySQL水平分库,涵盖分片策略、路由算法及零侵入配置... 目录一、ShardingSphere 简介1.1 对比1.2 核心概念1.3 Sharding-Sp

MySQL 表空却 ibd 文件过大的问题及解决方法

《MySQL表空却ibd文件过大的问题及解决方法》本文给大家介绍MySQL表空却ibd文件过大的问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考... 目录一、问题背景:表空却 “吃满” 磁盘的怪事二、问题复现:一步步编程还原异常场景1. 准备测试源表与数据

Spring创建Bean的八种主要方式详解

《Spring创建Bean的八种主要方式详解》Spring(尤其是SpringBoot)提供了多种方式来让容器创建和管理Bean,@Component、@Configuration+@Bean、@En... 目录引言一、Spring 创建 Bean 的 8 种主要方式1. @Component 及其衍生注解

Mac电脑如何通过 IntelliJ IDEA 远程连接 MySQL

《Mac电脑如何通过IntelliJIDEA远程连接MySQL》本文详解Mac通过IntelliJIDEA远程连接MySQL的步骤,本文通过图文并茂的形式给大家介绍的非常详细,感兴趣的朋友跟... 目录MAC电脑通过 IntelliJ IDEA 远程连接 mysql 的详细教程一、前缀条件确认二、打开 ID

MySQL的配置文件详解及实例代码

《MySQL的配置文件详解及实例代码》MySQL的配置文件是服务器运行的重要组成部分,用于设置服务器操作的各种参数,下面:本文主要介绍MySQL配置文件的相关资料,文中通过代码介绍的非常详细,需要... 目录前言一、配置文件结构1.[mysqld]2.[client]3.[mysql]4.[mysqldum

MySQL中查询和展示LONGBLOB类型数据的技巧总结

《MySQL中查询和展示LONGBLOB类型数据的技巧总结》在MySQL中LONGBLOB是一种二进制大对象(BLOB)数据类型,用于存储大量的二进制数据,:本文主要介绍MySQL中查询和展示LO... 目录前言1. 查询 LONGBLOB 数据的大小2. 查询并展示 LONGBLOB 数据2.1 转换为十