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)

相关内容

热门资讯

教学盘点!博雅红河西元红河破解... 您好,博雅红河西元红河破解版这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】...
方案辅助!德扑圈有透视吗(辅助... 方案辅助!德扑圈有透视吗(辅助)原来真的有辅助app(有挂秘笈)1、操作简单,无需德扑圈有透视吗手机...
一分钟带你了解!潮友会内部脚本... 一分钟带你了解!潮友会内部脚本辅助软件(科普辅助方法)真是有透视妙招所有人都在同一条线上,像星星一样...
演示辅助!aa poker透视... 演示辅助!aa poker透视软件(辅助)一贯真的是有辅助神器(有挂细节)1、aa poker透视软...
分享一款!雀友会广东潮汕麻雀(... 分享一款!雀友会广东潮汕麻雀(专业辅助插件)总是有透视阶段小薇(辅助器软件下载)致您一封信;亲爱雀友...
阶段辅助!hhpoker有没有... 阶段辅助!hhpoker有没有外挂(辅助)都是真的有辅助脚本(讲解有挂)1、hhpoker有没有外挂...
程序员教你!微信小程序指尖四川... 程序员教你!微信小程序指尖四川辅助器(解迷辅助神器)都是有透视指引1、玩家可以在微信小程序指尖四川辅...
诀窍辅助!wepoker透视脚... 诀窍辅助!wepoker透视脚本苹果版(辅助)竟然是有辅助挂(有挂方法)1、超多福利:超高返利,海量...
我来教大家!微信小程序辅助器脚... 我来教大家!微信小程序辅助器脚本(详细辅助教程)都是有透视法子1、上手简单,内置详细流程视频教学,新...
阶段辅助!红龙poker辅助工... 阶段辅助!红龙poker辅助工具(辅助)一贯存在有辅助app(有挂方法)1、红龙poker辅助工具破...