MySQL第一次作业

MySQL第一次作业

要求:

新建产品库mydb6_product,新建4张表如下:

employees表

列1:id,整型,主健

列2:name,字符串,最大长度50,不能为空

列3:age, 整型

列4:gender,字符串,最大长度10,不能为空,默认值"unknown"

:列5:salary, 浮点型

orders表

列1:id,整型,主键

列2:name,字符串,最大长度100,不能为空

列3:price,浮点型

列4:quantity,整型

列5:category, 字符串,最大长度50

invoices表

列1:number,整型,主键自增长

列2:order_id,整型,外键关联到orders表的id列

列3:in_date:日期型

列4:total_amount:浮点型,要求数据大于0

创建数据库mydb6_product:
mysql 复制代码
[root@localhost ~]# mysql -u root -p
mysql> create database mydb6_product;
Query OK, 1 row affected (0.00 sec)

创建表

创建employees表
mysql 复制代码
mysql> use mydb6_product;
Database changed
mysql> create table employees (
    -> id int primary key,
    -> name varchar(50) not null,
    -> age int,
    -> gender varchar(10) not null default 'unknown',
    -> salary float);

表结构:

创建orders表
mysql 复制代码
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.01 sec);

表结构:

创建invoices表
mysql 复制代码
mysql> create table invoices(
    -> number int auto_increment primary key,
    -> order_id int,
    -> in_date date,
    -> total_amount float check(total_amount > 0),
    -> foreign key (order_id) references orders(id));

表结构:

相关推荐
Leo.yuan9 分钟前
不同数据仓库模型有什么不同?企业如何选择适合的数据仓库模型?
大数据·数据库·数据仓库·信息可视化·spark
麦兜*25 分钟前
MongoDB 6.0 新特性解读:时间序列集合与加密查询
数据库·spring boot·mongodb·spring·spring cloud·系统架构
android_xc26 分钟前
Android Studio适配butterknife遇到的坑
android·ide·android studio·butterknife
chat2tomorrow28 分钟前
数据采集平台的起源与演进:从ETL到数据复制
大数据·数据库·数据仓库·mysql·低代码·postgresql·etl
稻草人想看远方31 分钟前
关系型数据库和非关系型数据库
数据库
考虑考虑32 分钟前
Postgerssql格式化时间
数据库·后端·postgresql
依稀i12335 分钟前
Spring Boot + MySQL 创建超级管理员
spring boot·mysql
2501_9159184140 分钟前
uni-app 项目 iOS 上架效率优化 从工具选择到流程改进的实战经验
android·ios·小程序·uni-app·cocoa·iphone·webview
千里码aicood40 分钟前
【springboot+vue】党员党建活动管理平台(源码+文档+调试+基础修改+答疑)
java·数据库·spring boot
00后程序员张1 小时前
如何在不同 iOS 设备上测试和上架 uni-app 应用 实战全流程解析
android·ios·小程序·https·uni-app·iphone·webview