MySQL第一次作业
创始人
2025-01-07 21:05:57
0

一、库的建立

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: 0  mysql> 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)

相关内容

热门资讯

近日!aa poker辅助,a... 近日!aa poker辅助,aapoker插件(透视)步骤教程(都是存在有挂)-哔哩哔哩1)aa p...
透视大纲!wepoker插件功... 透视大纲!wepoker插件功能辅助器,wepoker透视脚本免费(脚本)普及教程(一直真的是有挂)...
透视透视!如何下载wpk透视版... 透视透视!如何下载wpk透视版(透视)wpk透视辅助方法,教程绝活儿(有人有挂)-哔哩哔哩1、如何下...
今日!aapoker透视脚本,... 今日!aapoker透视脚本,aapoker透视脚本(透视)窍要教程(本来真的有挂)-哔哩哔哩1、让...
透视指南书!wepoker永久... 透视指南书!wepoker永久免费脚本,wepoker免费透视脚本(脚本)关于教程(都是有挂)-哔哩...
透视解密!wpk辅助(透视)w... 透视解密!wpk辅助(透视)wpk安卓下载辅助,教程练习(有挂详情)-哔哩哔哩wpk安卓下载辅助是不...
反观!aapoker公共底牌,... 反观!aapoker公共底牌,aapoker俱乐部靠谱吗(透视)法门教程(确实有挂)-哔哩哔哩1、全...
透视指南书!如何下载wepok... 透视指南书!如何下载wepoker安装包,wepoker能不能透视(脚本)开挂教程(确实真的是有挂)...
据公告内容!aapoker怎么... 据公告内容!aapoker怎么控制牌,aapoker透视插件(透视)模块教程(好像是有挂)-哔哩哔哩...
透视解迷!wpk德州局怎么透视... 透视解迷!wpk德州局怎么透视(透视)wpk俱乐部辅助器,教程诀窍(有挂规律)-哔哩哔哩1、wpk德...