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)

相关内容

热门资讯

避坑细节!决战卡五星看牌器(辅... 避坑细节!决战卡五星看牌器(辅助挂)总是真的有辅助攻略(有挂教程)1、每一步都需要思考,不同水平的挑...
玩家必看科普!吉安中至小程序微... 玩家必看科普!吉安中至小程序微信辅助(辅助挂)本来是有辅助脚本(详细教程)运吉安中至小程序微信辅助辅...
实测交流!蜀山四川游戏修改工具... 实测交流!蜀山四川游戏修改工具(辅助挂)好像真的有辅助技巧(发现有挂)1、很好的工具软件,可以解锁游...
玩家实测!小程序河北微乐脚本(... 玩家实测!小程序河北微乐脚本(辅助挂)本来真的是有辅助脚本(有挂方针)1、下载好小程序河北微乐脚本脚...
六分钟了解!皮皮游戏辅助器(辅... 六分钟了解!皮皮游戏辅助器(辅助挂)总是是有辅助插件(有人有挂)1、游戏颠覆性的策略玩法,独创攻略技...
据悉!开心泉州辅助器(辅助挂)... 据悉!开心泉州辅助器(辅助挂)切实真的有辅助插件(新版有挂)1、任何开心泉州辅助器透视是真的假的的玩...
一起来探讨!蜀门手游辅助免费脚... 一起来探讨!蜀门手游辅助免费脚本(辅助挂)其实是真的有辅助软件(真是有挂)暗藏猫腻,小编详细说明蜀门...
必备辅助推荐!雀神广东插件智能... 必备辅助推荐!雀神广东插件智能解码(辅助挂)本来存在有辅助挂(有挂分析)运雀神广东插件智能解码辅助工...
截至发稿!开心庄园辅助器免费(... 截至发稿!开心庄园辅助器免费(辅助挂)果然真的有辅助器(真的有挂)1、让任何用户在无需开心庄园辅助器...
必备攻略!玖玖互娱辅助工具(辅... 必备攻略!玖玖互娱辅助工具(辅助挂)真是是有辅助攻略(果真有挂)1、玖玖互娱辅助工具有没有辅助教程、...