当前位置: 首页 > news >正文

MySQL第一次作业

一、库的建立

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydb2_stuinfo      |
| mydb3_employee     |
| mydb4_product      |
| mydbl_test         |
| mysql              |
| performance_schema |
| sys                |
| temp2              |
+--------------------+
9 rows in set (0.00 sec)mysql> create database mydb6_product;
Query OK, 1 row affected (0.01 sec)mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydb2_stuinfo      |
| mydb3_employee     |
| mydb4_product      |
| mydb6_product      |
| mydbl_test         |
| mysql              |
| performance_schema |
| sys                |
| temp2              |
+--------------------+
10 rows in set (0.00 sec)

二、建立employees表  (有主键,非空,默认值的要求)

mysql> create table employees(-> id int primary key,-> name varchar(50) not null,-> age int,-> gender varchar(10) not null default 'unknown',-> salary float);
Query OK, 0 rows affected (0.03 sec)mysql> desc employees;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id     | int         | NO   | PRI | NULL    |       |
| name   | varchar(50) | NO   |     | NULL    |       |
| age    | int         | YES  |     | NULL    |       |
| gender | varchar(10) | NO   |     | unknown |       |
| salary | float       | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

三、建立 orders表 (有主键和非空的要求)

​
mysql> create table orders(-> id int primary key,-> name varchar(100) not null,-> price float,-> quantity int,-> category varchar(50));
Query OK, 0 rows affected (0.03 sec)mysql> desc orders;
+----------+--------------+------+-----+---------+-------+
| Field    | Type         | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| id       | int          | NO   | PRI | NULL    |       |
| name     | varchar(100) | NO   |     | NULL    |       |
| price    | float        | YES  |     | NULL    |       |
| quantity | int          | YES  |     | NULL    |       |
| category | varchar(50)  | YES  |     | NULL    |       |
+----------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)​

四、建立invoices表 (有主键自增长,外键关联,数值范围的要求)

mysql> create table invoices(-> number int primary key,-> order_id int,foreign key (order_id) references orders(id),-> in_date date,-> total_amount float ,check(total_amount>0));
Query OK, 0 rows affected (0.04 sec)mysql> alter table invoices modify number int auto_increment;
Query OK, 0 rows affected (0.06 sec)
Records: 0  Duplicates: 0  Warnings: 0mysql> desc invoices;
+--------------+-------+------+-----+---------+----------------+
| Field        | Type  | Null | Key | Default | Extra          |
+--------------+-------+------+-----+---------+----------------+
| number       | int   | NO   | PRI | NULL    | auto_increment |
| order_id     | int   | YES  | MUL | NULL    |                |
| in_date      | date  | YES  |     | NULL    |                |
| total_amount | float | YES  |     | NULL    |                |
+--------------+-------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

相关文章:

  • 数据库day2
  • 伪元素::before :: after的用法?
  • 微软GraphRAG +本地模型+Gradio 简单测试笔记
  • 【C#】Array和List
  • 深入解析公有IP与私有IP:地址分配与使用限制
  • 智慧农业新纪元:解锁新质生产力,加速产业数字化转型
  • liosam复现
  • 测试面试宝典(六)—— 请回答集成测试和系统测试的区别,以及它们的应用场景主要是什么?
  • 索引堆及其优化
  • Qt模型/视图架构——委托(delegate)
  • 【日常记录】【CSS】display:inline 的样式截断
  • Java基础笔记(面试题)
  • 抖音短视频seo矩阵系统源码(搭建技术开发分享)
  • 前端开发体系+html文件详解
  • live555关于RTSP协议交互流程
  • [译] 怎样写一个基础的编译器
  • 2018天猫双11|这就是阿里云!不止有新技术,更有温暖的社会力量
  • centos安装java运行环境jdk+tomcat
  • docker容器内的网络抓包
  • iOS | NSProxy
  • iOS 系统授权开发
  • SpingCloudBus整合RabbitMQ
  • 大整数乘法-表格法
  • 开源地图数据可视化库——mapnik
  • 利用DataURL技术在网页上显示图片
  • 两列自适应布局方案整理
  • 配置 PM2 实现代码自动发布
  • 如何邀请好友注册您的网站(模拟百度网盘)
  • 设计模式(12)迭代器模式(讲解+应用)
  • 阿里云移动端播放器高级功能介绍
  • ​Benvista PhotoZoom Pro 9.0.4新功能介绍
  • ​云纳万物 · 数皆有言|2021 七牛云战略发布会启幕,邀您赴约
  • # 日期待t_最值得等的SUV奥迪Q9:空间比MPV还大,或搭4.0T,香
  • $forceUpdate()函数
  • (10)ATF MMU转换表
  • (STM32笔记)九、RCC时钟树与时钟 第一部分
  • (二)基于wpr_simulation 的Ros机器人运动控制,gazebo仿真
  • (附源码)springboot太原学院贫困生申请管理系统 毕业设计 101517
  • (附源码)计算机毕业设计ssm本地美食推荐平台
  • (附源码)计算机毕业设计ssm基于B_S的汽车售后服务管理系统
  • (十八)Flink CEP 详解
  • (收藏)Git和Repo扫盲——如何取得Android源代码
  • (一)C语言之入门:使用Visual Studio Community 2022运行hello world
  • (转)h264中avc和flv数据的解析
  • (转)菜鸟学数据库(三)——存储过程
  • ../depcomp: line 571: exec: g++: not found
  • .net CHARTING图表控件下载地址
  • .Net Core中的内存缓存实现——Redis及MemoryCache(2个可选)方案的实现
  • .net 反编译_.net反编译的相关问题
  • .NET 中小心嵌套等待的 Task,它可能会耗尽你线程池的现有资源,出现类似死锁的情况
  • .net 桌面开发 运行一阵子就自动关闭_聊城旋转门家用价格大约是多少,全自动旋转门,期待合作...
  • .net反编译工具
  • .net连接MySQL的方法
  • .NET使用存储过程实现对数据库的增删改查
  • .php文件都打不开,打不开php文件怎么办