目录
一:创建数据库
二:创建表
2.1:创建employees表
2.2:创建orders表
2.3:创建invoices表
一:创建数据库
mysql> create database mydb6_product;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
mysql> use mydb6_product;
Database changed
mysql> select database();
二:创建表
2.1:创建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);
2.2:创建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.02 sec)
2.3:创建invoices表
mysql> create table invoices (number int primary key,
-> order_id int ,
-> in_date date,
-> total_amount float,
-> foreign key (order_id) references orders(id) );
mysql> alter table invoices modify number int auto_increment;
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0