SQL入门学习

SQL(Structured Query Language,结构化查询语言)是一种特定目的编程语言,用于管理关系数据库管理系统(RDBMS),或在关系流数据管理系统(RDSMS)中进行流处理。SQL基于关系代数和元组关系演算,包括一个数据定义语言和数据操纵语言。SQL的范围包括数据插入、查询、更新和删除,数据库模式创建和修改,以及数据访问控制。尽管SQL经常被描述为,而且很大程度上是一种声明式编程(4GL),但是其也含有过程式编程的元素。SQL是对Edgar Frank Codd的关系模型的第一个商业化语言实现,这一模型在其1970年的一篇具有影响力的论文《一个对于大型共享型数据库的关系模型》(A Relational Model of Data for Large Shared Data Banks)中被描述。尽管SQL并非完全按照E.F Codd的关系模型设计,但其依然成为最为广泛运用的数据库语言。

基础概念

1.数据库(database):保存有组织的数据的容器(通常是一个文件或一组文件)。

1.数据库软件称为数据库管理系统(DBMS),数据库是通过DBMS创建和操纵的容器。

2.主要的DBMS:

  • IBM DB2(包括云上 DB2)
  • Microsoft SQL Server(包括 Microsoft SQL Server Express)
  • MariaDB
  • MySQL
  • Oracle(包括 Oracle Express)
  • PostgreSQL
  • SQLite

2.表(table):某种特定类型数据的结构化清单。

1.存储在表中的数据是同一种类型的数据或清单。

2.数据库中的每个表都有一个名字来标识自己。该名字是唯一的,即数据库中没有其他表具有相同的名字。

3.不同的数据库中可以使用相同的表名。

3.模式(schema):关于数据库和表的布局及特性的信息。

表具有特性,这些特性定义数据在表中如何存储,包括存储什么样的数据,数据如何分解,各部分信息如何命名等信息。描述表的这组信息就是模式(schema),模式可以用来描述数据库中特定的表,也可以用来描述整个数据库(和其中表的关系)。

4.列(column):表中的一个字段。所有表都是由一个或多个列组成的。

1.表由列组成,列存储表中某部分的信息。

2.根据具体需求来决定把数据分解到何种程度。

5.数据类型(datatype):允许什么类型的数据。每个表列都有相应的数据类型,它限制(或允许)该列中存储的数据。

1.数据类型限定了可存储在列中的数据种类(如防止在数值字段中录入字符值)。

2.数据类型还帮助正确地分类数据,并在优化磁盘使用方面起重要的作用。

6.行(row):表中的一个记录。(数据库记录,record)

1.表中的数据是按行存储的,所保存的每个记录存储在自己的行内。如果将表想象为网格,网格中垂直的列为表列,水平行为表行,如顾客表可以每行存储一个顾客。

7.主键(primary key):一列(或几列),其值能够唯一标识表中每一行。

1.主键用来表示一个特定的行

2.应该总是定义主键,以便于以后的数据操作和管理。

3.表中的任何列都可以作为主键,只要满足以下条件:

  • 任意两行都不具有相同的主键值
  • 每一行都必须具有一个主键值(主键列不允许空值NULL)
  • 主键列中的值不允许修改或更新
  • 主键值不能重用(如果某行从表中删除,它的主键不能赋给以后的新行

4.使用多个列作为主键时,所有列值的组合必须是唯一的(但其中单个列的值可以不唯一)。

8.SQL(Structured Query Language,结构化查询语言),一种专门用来与数据库沟通的语言。

1.SQL不是某个特定数据库厂商专有的语言。绝大多数重要的 DBMS都支持SQL。

2.SQL简单易学。

3.灵活使用SQL语言元素,可以进行复杂和高级的数据库操作。

4.许多DBMS厂商通过增加语句或指令,对SQL进行扩展,目的是提供执行特定操作的额外功能或简化方法。

5.标准SQL由ANSI标准委员会管理,从而称为ANSI QL。所有主要的DBMS,即使有自己的扩展,也都支持ANSI SQL。各个实现有自己的名称,如 Oracle的PL/SQL、微软SQL Server的 Transact-SQL等。

9.关键字(keyword):作为SQL组成部分的保留字。关键字不能用作表或列的名字。

在命名数据库、表、列和其他数据库对象时,不要使用关键字。

1 2 3 4


检索数据

1.每个SQL语句都是由一个或多个关键字构成的。

2.多条SQL语句必须以分号(;)分隔。多数DBMS不需要在单条SQL语句后加分号。(尽量加上分号)

3.SQL语句不区分大小写,习惯上SQL关键字大写,而对列名和表名小写。

4.处理SQL语句时其中所有空格都被忽略。SQL语句可以写成一行,也可以分写在多行。(将SQL语句分成多行更容易阅读和调试)

1
2
3
4
5
6
7
8
9
SELECT prod_name 
FROM Products;

SELECT prod_name FROM Products;

SELECT
prod_name
FROM
Products;

SELECT

从一个或多个表中检索信息


检索单个列

1
2
SELECT 列名
FROM 表名;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#从Products表中检索一个名为prod_name的列。所需的列名写在SELECT关键字之后,FROM关键字指出从哪个表中检索数据。
mysql> SELECT prod_name
-> FROM Products;
+---------------------+
| prod_name |
+---------------------+
| Fish bean bag toy |
| Bird bean bag toy |
| Rabbit bean bag toy |
| 8 inch teddy bear |
| 12 inch teddy bear |
| 18 inch teddy bear |
| Raggedy Ann |
| King doll |
| Queen doll |
+---------------------+
9 rows in set (0.00 sec)

检索多个列

在选择多个列时,一定要在列名之间加上逗号,但最后一个列名后不加。如果在最后一个列名后加了逗号,将出现错误。

1
2
SELECT 列名1,列名2,列名3
FROM 表名;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mysql> SELECT prod_name,prod_id,prod_price
-> FROM Products;
+---------------------+---------+------------+
| prod_name | prod_id | prod_price |
+---------------------+---------+------------+
| Fish bean bag toy | BNBG01 | 3.49 |
| Bird bean bag toy | BNBG02 | 3.49 |
| Rabbit bean bag toy | BNBG03 | 3.49 |
| 8 inch teddy bear | BR01 | 5.99 |
| 12 inch teddy bear | BR02 | 8.99 |
| 18 inch teddy bear | BR03 | 11.99 |
| Raggedy Ann | RGAN01 | 4.99 |
| King doll | RYL01 | 9.49 |
| Queen doll | RYL02 | 9.49 |
+---------------------+---------+------------+
9 rows in set (0.00 sec)

检索所有列

1.SELECT语句还可以检索所有的列,在实际列名的位置使用星号(*)通配符即可。

2.使用通配符可检索出名字未知的列。

1
2
SELECT * 
FROM 表名;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mysql> SELECT *
-> FROM Products;
+---------+---------+---------------------+------------+-----------------------------------------------------------------------+
| prod_id | vend_id | prod_name | prod_price | prod_desc |
+---------+---------+---------------------+------------+-----------------------------------------------------------------------+
| BNBG01 | DLL01 | Fish bean bag toy | 3.49 | Fish bean bag toy, complete with bean bag worms with which to feed it |
| BNBG02 | DLL01 | Bird bean bag toy | 3.49 | Bird bean bag toy, eggs are not included |
| BNBG03 | DLL01 | Rabbit bean bag toy | 3.49 | Rabbit bean bag toy, comes with bean bag carrots |
| BR01 | BRS01 | 8 inch teddy bear | 5.99 | 8 inch teddy bear, comes with cap and jacket |
| BR02 | BRS01 | 12 inch teddy bear | 8.99 | 12 inch teddy bear, comes with cap and jacket |
| BR03 | BRS01 | 18 inch teddy bear | 11.99 | 18 inch teddy bear, comes with cap and jacket |
| RGAN01 | DLL01 | Raggedy Ann | 4.99 | 18 inch Raggedy Ann doll |
| RYL01 | FNG01 | King doll | 9.49 | 12 inch king doll with royal garments and crown |
| RYL02 | FNG01 | Queen doll | 9.49 | 12 inch queen doll with royal garments and crown |
+---------+---------+---------------------+------------+-----------------------------------------------------------------------+
9 rows in set (0.00 sec)

检索不同值

1.DISTINCT:指示数据库只返回不同的值(直接放在列名的前面)。

2.DISTINCT关键字作用于所有的列。

1
2
SELECT DISTINCT 列名 
FROM 表名;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mysql> SELECT vend_id
-> FROM Products;
+---------+
| vend_id |
+---------+
| BRS01 |
| BRS01 |
| BRS01 |
| DLL01 |
| DLL01 |
| DLL01 |
| DLL01 |
| FNG01 |
| FNG01 |
+---------+
9 rows in set (0.01 sec)
1
2
3
4
5
6
7
8
9
10
11
#SELECT DISTINCT vend_id 告诉DBMS只返回不同(具有唯一性)的vend_id 行
mysql> SELECT DISTINCT vend_id
-> FROM Products;
+---------+
| vend_id |
+---------+
| BRS01 |
| DLL01 |
| FNG01 |
+---------+
3 rows in set (0.01 sec)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#指定的两列组合起来有6个不同的结果
mysql> SELECT DISTINCT vend_id,prod_price FROM Products;
+---------+------------+
| vend_id | prod_price |
+---------+------------+
| DLL01 | 3.49 |
| BRS01 | 5.99 |
| BRS01 | 8.99 |
| BRS01 | 11.99 |
| DLL01 | 4.99 |
| FNG01 | 9.49 |
+---------+------------+
6 rows in set (0.01 sec)

mysql> SELECT vend_id,prod_price FROM Products;
+---------+------------+
| vend_id | prod_price |
+---------+------------+
| DLL01 | 3.49 |
| DLL01 | 3.49 |
| DLL01 | 3.49 |
| BRS01 | 5.99 |
| BRS01 | 8.99 |
| BRS01 | 11.99 |
| DLL01 | 4.99 |
| FNG01 | 9.49 |
| FNG01 | 9.49 |
+---------+------------+
9 rows in set (0.00 sec)


限制结果

1.SQL Server:限制最多返回多少行(TOP)

1
2
SELECT TOP 5 prod_name
FROM Products;

2.DB2

1
2
3
SELECT prod_name
FROM Products
FETCH FIRST 5 ROWS ONLY;

3.Oracle:ROWNUM(行计数器)

1
2
3
SELECT prod_name
FROM Products
WHERE ROWNUM <=5;

4.MySQL、MariaDB、PostgreSQL、SQLite:LIMIT(检索行数) OFFSET(起始行数)

  • 第一个被检索的行是第0行,如LIMIT 1 OFFSET 1会检索第2行。
  • MySQL、MariaDB和SQLite可以把LIMIT 4 OFFSET 3语句简化为LIMIT 3,4。逗号之前的值对应OFFSET,逗号之后的值对应LIMIT。
1
2
3
4
5
6
7
SELECT prod_name
FROM Products
LIMIT 5;

SELECT prod_name
FROM Products
LIMIT 5 OFFSET 5;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
mysql> SELECT prod_name
-> FROM Products;
+---------------------+
| prod_name |
+---------------------+
| Fish bean bag toy |
| Bird bean bag toy |
| Rabbit bean bag toy |
| 8 inch teddy bear |
| 12 inch teddy bear |
| 18 inch teddy bear |
| Raggedy Ann |
| King doll |
| Queen doll |
+---------------------+
9 rows in set (0.00 sec)

#LIMIT 5指示MySQL等DBMS返回不超过5行的数据
mysql> SELECT prod_name
-> FROM Products
-> LIMIT 5;
+---------------------+
| prod_name |
+---------------------+
| Fish bean bag toy |
| Bird bean bag toy |
| Rabbit bean bag toy |
| 8 inch teddy bear |
| 12 inch teddy bear |
+---------------------+
5 rows in set (0.01 sec)

#LIMIT 5 OFFSET 5 指示 MySQL等DBMS返回从第5行起的5行数据
mysql> SELECT prod_name
-> FROM Products
-> LIMIT 5
-> OFFSET 5;
+--------------------+
| prod_name |
+--------------------+
| 18 inch teddy bear |
| Raggedy Ann |
| King doll |
| Queen doll |
+--------------------+
4 rows in set (0.00 sec)

mysql> SELECT prod_name
-> FROM Products
-> LIMIT 2,5;
+---------------------+
| prod_name |
+---------------------+
| Rabbit bean bag toy |
| 8 inch teddy bear |
| 12 inch teddy bear |
| 18 inch teddy bear |
| Raggedy Ann |
+---------------------+
5 rows in set (0.00 sec)

注释

1.行内注释

  • --:(两个连字符)嵌在行内,--之后的文本就是注释。
  • #:有些DBMS不支持。

2.多行注释

  • 注释从/*开始,到*/结束,/**/之间的任何内容都是注释,常用于注释代码。

排序检索数据

Table Scripts

  • MySQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
-----------------------------------------------------
-- Sams Teach Yourself SQL in 10 Minutes, 5th Edition
-- http://forta.com/books/0135182794/
-- Example table creation scripts for MySQL & MariaDB
-----------------------------------------------------


-- ----------------------
-- Create Customers table
-- ----------------------
CREATE TABLE Customers
(
cust_id char(10) NOT NULL ,
cust_name char(50) NOT NULL ,
cust_address char(50) NULL ,
cust_city char(50) NULL ,
cust_state char(5) NULL ,
cust_zip char(10) NULL ,
cust_country char(50) NULL ,
cust_contact char(50) NULL ,
cust_email char(255) NULL
);

-- -----------------------
-- Create OrderItems table
-- -----------------------
CREATE TABLE OrderItems
(
order_num int NOT NULL ,
order_item int NOT NULL ,
prod_id char(10) NOT NULL ,
quantity int NOT NULL ,
item_price decimal(8,2) NOT NULL
);


-- -------------------
-- Create Orders table
-- -------------------
CREATE TABLE Orders
(
order_num int NOT NULL ,
order_date datetime NOT NULL ,
cust_id char(10) NOT NULL
);

-- ---------------------
-- Create Products table
-- ---------------------
CREATE TABLE Products
(
prod_id char(10) NOT NULL ,
vend_id char(10) NOT NULL ,
prod_name char(255) NOT NULL ,
prod_price decimal(8,2) NOT NULL ,
prod_desc text NULL
);

-- --------------------
-- Create Vendors table
-- --------------------
CREATE TABLE Vendors
(
vend_id char(10) NOT NULL ,
vend_name char(50) NOT NULL ,
vend_address char(50) NULL ,
vend_city char(50) NULL ,
vend_state char(5) NULL ,
vend_zip char(10) NULL ,
vend_country char(50) NULL
);


-- -------------------
-- Define primary keys
-- -------------------
ALTER TABLE Customers ADD PRIMARY KEY (cust_id);
ALTER TABLE OrderItems ADD PRIMARY KEY (order_num, order_item);
ALTER TABLE Orders ADD PRIMARY KEY (order_num);
ALTER TABLE Products ADD PRIMARY KEY (prod_id);
ALTER TABLE Vendors ADD PRIMARY KEY (vend_id);


-- -------------------
-- Define foreign keys
-- -------------------
ALTER TABLE OrderItems ADD CONSTRAINT FK_OrderItems_Orders FOREIGN KEY (order_num) REFERENCES Orders (order_num);
ALTER TABLE OrderItems ADD CONSTRAINT FK_OrderItems_Products FOREIGN KEY (prod_id) REFERENCES Products (prod_id);
ALTER TABLE Orders ADD CONSTRAINT FK_Orders_Customers FOREIGN KEY (cust_id) REFERENCES Customers (cust_id);
ALTER TABLE Products ADD CONSTRAINT FK_Products_Vendors FOREIGN KEY (vend_id) REFERENCES Vendors (vend_id);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
-------------------------------------------------------
-- Sams Teach Yourself SQL in 10 Minutes, 5th Edition
-- http://forta.com/books/0135182794/
-- Example table population scripts for MySQL & MariaDB
-------------------------------------------------------


-- ------------------------
-- Populate Customers table
-- ------------------------
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000001', 'Village Toys', '200 Maple Lane', 'Detroit', 'MI', '44444', 'USA', 'John Smith', 'sales@villagetoys.com');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact)
VALUES('1000000002', 'Kids Place', '333 South Lake Drive', 'Columbus', 'OH', '43333', 'USA', 'Michelle Green');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000003', 'Fun4All', '1 Sunny Place', 'Muncie', 'IN', '42222', 'USA', 'Jim Jones', 'jjones@fun4all.com');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000004', 'Fun4All', '829 Riverside Drive', 'Phoenix', 'AZ', '88888', 'USA', 'Denise L. Stephens', 'dstephens@fun4all.com');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact)
VALUES('1000000005', 'The Toy Store', '4545 53rd Street', 'Chicago', 'IL', '54545', 'USA', 'Kim Howard');

-- ----------------------
-- Populate Vendors table
-- ----------------------
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES('BRS01','Bears R Us','123 Main Street','Bear Town','MI','44444', 'USA');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES('BRE02','Bear Emporium','500 Park Street','Anytown','OH','44333', 'USA');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES('DLL01','Doll House Inc.','555 High Street','Dollsville','CA','99999', 'USA');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES('FRB01','Furball Inc.','1000 5th Avenue','New York','NY','11111', 'USA');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES('FNG01','Fun and Games','42 Galaxy Road','London', NULL,'N16 6PS', 'England');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES('JTS01','Jouets et ours','1 Rue Amusement','Paris', NULL,'45678', 'France');

-- -----------------------
-- Populate Products table
-- -----------------------
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('BR01', 'BRS01', '8 inch teddy bear', 5.99, '8 inch teddy bear, comes with cap and jacket');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('BR02', 'BRS01', '12 inch teddy bear', 8.99, '12 inch teddy bear, comes with cap and jacket');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('BR03', 'BRS01', '18 inch teddy bear', 11.99, '18 inch teddy bear, comes with cap and jacket');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('BNBG01', 'DLL01', 'Fish bean bag toy', 3.49, 'Fish bean bag toy, complete with bean bag worms with which to feed it');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('BNBG02', 'DLL01', 'Bird bean bag toy', 3.49, 'Bird bean bag toy, eggs are not included');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('BNBG03', 'DLL01', 'Rabbit bean bag toy', 3.49, 'Rabbit bean bag toy, comes with bean bag carrots');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('RGAN01', 'DLL01', 'Raggedy Ann', 4.99, '18 inch Raggedy Ann doll');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('RYL01', 'FNG01', 'King doll', 9.49, '12 inch king doll with royal garments and crown');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('RYL02', 'FNG01', 'Queen doll', 9.49, '12 inch queen doll with royal garments and crown');

-- ---------------------
-- Populate Orders table
-- ---------------------
INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20005, '2020-05-01', '1000000001');
INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20006, '2020-01-12', '1000000003');
INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20007, '2020-01-30', '1000000004');
INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20008, '2020-02-03', '1000000005');
INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20009, '2020-02-08', '1000000001');

-- -------------------------
-- Populate OrderItems table
-- -------------------------
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20005, 1, 'BR01', 100, 5.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20005, 2, 'BR03', 100, 10.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20006, 1, 'BR01', 20, 5.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20006, 2, 'BR02', 10, 8.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20006, 3, 'BR03', 10, 11.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 1, 'BR03', 50, 11.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 2, 'BNBG01', 100, 2.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 3, 'BNBG02', 100, 2.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 4, 'BNBG03', 100, 2.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 5, 'RGAN01', 50, 4.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 1, 'RGAN01', 5, 4.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 2, 'BR03', 5, 11.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 3, 'BNBG01', 10, 3.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 4, 'BNBG02', 10, 3.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 5, 'BNBG03', 10, 3.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20009, 1, 'BNBG01', 250, 2.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20009, 2, 'BNBG02', 250, 2.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20009, 3, 'BNBG03', 250, 2.49);