1.创建数据库sqlsz
create database sqlsz; #创建数据库
show databases; #显示所有数据库
use sqlsz; #选择数据库
![](https://img.haomeiwen.com/i16423381/131090618da90e68.png)
2.创建表
(1)命令行创建表customers
CREATE TABLE customers #关键字用大写字母,创建表
(
cust_id int NOT NULL AUTO_INCREMENT, #表的第一列,数据类型为int,不能为空,自动增量
cust_name char(50) NOT NULL, #表得第二列,数据类型为char,长度为50个字符,不能为空
cust_address char(50) NULL, #允许为空
cust_city char(50) NULL,
cust_state char(50) NULL,
cust_zip char(50) NULL,
cust_country char(50) NULL,
cust_contact char(50) NULL,
cust_email char(255) NULL, #字符型数据类型,长度为255
PRIMARY KEY (cust_id) #创建主键
)ENGINE=InnoDB; #表内容结束,用),Mysql语句结束用;,选择引擎
![](https://img.haomeiwen.com/i16423381/88ffc4e01166d3a5.png)
![](https://img.haomeiwen.com/i16423381/4c1e1d4bc1f081b6.png)
3.查看表
SHOW COLUMNS FROM customers;
DESCRIBE customers;
DESC customers;
以上三种方式都可以。
![](https://img.haomeiwen.com/i16423381/a129e34420cf5e90.png)
4.其他5个表,按照同样的方式创建
![](https://img.haomeiwen.com/i16423381/769555a9413aaa9f.png)
网友评论