数据库创建表并插入数据练习题

一、创建表的要求

创建一个英雄表(hero)
主键
name
nickname
address
groups
email
telphone

二、 操作步骤

1.登录MySQL

[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.32 Source distributionCopyright (c) 2000, 2023, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| db_han             |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

2.创建数据库和表

注意:关键词建议用大写

mysql> create database db_hero;
Query OK, 1 row affected (0.00 sec)mysql> use db_hero;        #这句可以不跟分号
Database changed
mysql> create table if not exists t_hero (-> id int primary key auto_increment,-> name varchar(50) not null unique,-> nickname varchar(255),-> address varchar(50),-> `groups` varchar(25),        #注意:groups是关键字,则需用反引号引起或稍做改变这个单词-> email varchar(50),-> telphone varchar(11) unique-> );
Query OK, 0 rows affected (0.02 sec)

3. 插入数据

mysql> insert into t_hero values (null,"宋江","及时雨",null,"水浒传","songjiang@qq.com","15112346666");
Query OK, 1 row affected (0.00 sec)mysql> insert into t_hero values (null,"吴用","智多星",null,"水浒传","wuyong@qq.com","15122331144");
Query OK, 1 row affected (0.01 sec)mysql> insert into t_hero values (null,"林冲","豹子头",null,"水浒传","linchong@qq.com","15111223456");
Query OK, 1 row affected (0.01 sec)mysql> insert into t_hero values (null,"鲁智深","花和尚",null,"水浒传","luzhishen@qq.com","15199884567");
Query OK, 1 row affected (0.00 sec)mysql> insert into t_hero values (null,"武松","行者",null,"水浒传","wusong@qq.com","15145663245");
Query OK, 1 row affected (0.00 sec)mysql> insert into t_hero values (null,"李逵","黑旋风",null,"水浒传","likui@qq.com","15145456767");
Query OK, 1 row affected (0.00 sec)mysql> insert into t_hero values (null,"刘备","玄德","河北涿州","三国演义","liubei@qq.com","15298675544");
Query OK, 1 row affected (0.00 sec)mysql> insert into t_hero values (null,"沙僧","沙和尚","天宫卷帘大将","西游记","shaseng@qq.com","15544338877");
Query OK, 1 row affected (0.00 sec)mysql> insert into t_hero values (null,"关羽","美髯公","山西运城","三国演义","guanyu@qq.com","15233556633");
Query OK, 1 row affected (0.00 sec)mysql> insert into t_hero values (null,"张飞","翼德",null,"三国演义","zhangfei@qq.com","15244331234");
Query OK, 1 row affected (0.00 sec)mysql> insert into t_hero values (null,"猪八戒","天蓬元帅","天宫将领","西游记","zhubajie@qq.com","15545673221");
Query OK, 1 row affected (0.00 sec)mysql> insert into t_hero values (null,"赵云","常胜将军",null,"三国演义","zhaoyun@qq.com","15212344321");
Query OK, 1 row affected (0.00 sec)mysql> insert into t_hero values (null,"诸葛亮","卧龙","山东临沂市沂南县","三国演义","zhugeliang@qq.com","15299776543");
Query OK, 1 row affected (0.00 sec)mysql> insert into t_hero values (null,"孙悟空","齐天大圣","花果山","西游记","sunwukong@qq.com","15532423432");
Query OK, 1 row affected (0.00 sec)mysql> insert into t_hero values (null,"贾宝玉","宝二爷","荣国府","红楼梦","jiabaoyu@qq.com","17732467632");
Query OK, 1 row affected (0.00 sec)mysql> insert into t_hero values (null,"唐僧","玄奘","大唐","西游记","tangseng@qq.com","15534543678");
Query OK, 1 row affected (0.00 sec)mysql> insert into t_hero values (null,"林黛玉","潇湘妃子","荣国府外戚","红楼梦","lindaiyu@qq.com","17744557654");
Query OK, 1 row affected (0.00 sec)

4.查看表内容

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/344241.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【网络安全】【密码学】【北京航空航天大学】实验三、数论基础(下)【C语言实现】

实验三、数论基础(下) 一、实验内容 1、中国剩余定理(Chinese Remainder Theorem) (1)、算法原理 m1, m2, … mk 是一组两两互素的正整数,且 M m1 m2 … mk 为它们的乘积, 则如下的同余…

使用new pm写一个pass

范例来自LLVM Techniques, Tips, and Best Practices Clang and Middle-End Libraries llvm ir到ir是由一个个pass处理的,从一个ir到另一个ir会改变一些东西 书里面就是说想要给指针变量添加一个noalias属性 书里面使用插件的形式,但是不知道怎么我搞不…

MetaGPT前期准备与快速上手

大家好,MetaGPT 是基于大型语言模型(LLMs)的多智能体协作框架,GitHub star数量已经达到31.3k。 接下来我们聊一下快速上手 这里写目录标题 一、环境搭建1.python 环境2. MetaGpt 下载 二、MetaGPT配置1.调用 ChatGPT API 服务2.简…

手机扫一扫文档、证件表格就能打印,不用专门找扫描软件啦

现在各大品牌的手机扫一扫功能都可以满足扫描文档、扫描表格的功能,平常如果需要将纸质文件扫描成电子档,拿起手机就可以实现。文件签名后再扫描成PDF版本,相信大家都用得不少了。 今天就用华为手机的扫一扫给大家示范一下如何将文档、证件、…

设计模式—行为型模式之状态模式

设计模式—行为型模式之状态模式 状态(State)模式:对有状态的对象,把复杂的“判断逻辑”提取到不同的状态对象中,允许状态对象在其内部状态发生改变时改变其行为。 状态模式包含以下主要角色: 环境类&am…

Kafka配置Kerberos安全认证及与Java程序集成

Background 本文主要介绍在 Kafka 中如何配置 Kerberos 认证,以及 java 使用 JAAS 来进行 Kerberos 认证连接。本文演示为单机版。 所用软件版本 查看 Kerberos 版本命令:klist -V 软件名称版本jdk1.8.0_202kafka2.12-2.2.1kerberos1.15.1 1、Kerberos …

【STM32】STM32学习笔记-串口发送和接收(27)

00. 目录 文章目录 00. 目录01. 串口简介02. 串口相关API2.1 USART_Init2.2 USART_InitTypeDef2.3 USART_Cmd2.4 USART_SendData2.5 USART_ReceiveData 03. 串口发送接线图04. USB转串口模块05. 串口发送程序示例06. 串口发送支持printf07. 串口发送支持printf_v208.09.10. 01.…

Linux网络基础及bonding实际操作

1.查看linux基础的网络配置 网关:route -n ip地址:ifconfig 或 ip a DNS服务器:cat /etc/resolv.conf 主机名:hostname 路由:route -n 网络连接状态:ss 或 netstat 2.临时修改网卡名称 3.永久修…

在全志T113-i平台上实现H.265视频解码步骤详解

H.265,也被称为HEVC(HighEfficiency Video Coding),作为H.264的继任者,提供了更好的视频压缩和更高的视频质。H.265通过引入更多先进的编码技术,如更强大的运动估计和更高效的变换编码,对比H.264进行了改进。这些改进使…

宏景eHR 多处 SQL注入漏洞复现

0x01 产品简介 宏景eHR人力资源管理软件是一款人力资源管理与数字化应用相融合,满足动态化、协同化、流程化、战略化需求的软件。 0x02 漏洞概述 宏景eHR view、trainplan_tree.jsp等接口处存在SQL注入漏洞,未经过身份认证的远程攻击者可利用此漏洞执行任意SQL指令,从而窃…

Python web自动化测试框架搭建(功能接口)——通用模块

1、通用模块: config.conf: 公共配置文件,配置报告、日志、截图路径,以及邮件相关配置 [report] reportpath E:\workspace\WebAutomation\src\functiontest\Report\2017-07-18 screen_path E:\workspace\WebAutomation\src\functiontest\R…

vue上传文件加进度条,fake-progress一起使用

el-upload上传过程中加进度条,进度条el-progress配合fake-progress一起使用,效果如下: 安装 npm install fake-progress 在用到的文件里面引用 import Fakeprogress from "fake-progress"; 这个进度条主要是假的进度条&#xff…