2.5  select

SELECT       要返回的列或表达式     是
FROM          从中检索数据的表        仅在从表选择数据时使用
WHERE        行级过滤                      否
GROUP BY  分组说明                      仅在按组计算聚集时使用
HAVING        组级过滤                      否
ORDER BY  输出排序顺序               否

SELECT DISTINCT vend_id, prod_price --会列出二列数据不相同每行不同的数据
FROM Products;

3.1排序

SELECT prod_id, prod_price, prod_name
FROM Products
ORDER BY prod_price, prod_name;   --排序 先排prod_price顺序,然后在其基础上排prod_name
SELECT prod_id, prod_price, prod_name
FROM Products
, 2;  --先排第3列,在其基础上排第2列
SELECT prod_id, prod_price, prod_name
FROM Products
ORDER BY  prod_name DESC,prod_price DESC; --DESC是反转,先排前面的,再排后面的

4.1where

排序ORDER BY应该在where之后

where的字段不是一定要在select里出现的

''单引号用来限定字符串,与数值

<> != 不等于 注:Access支持<>不支持!=
!   不(非) 不可单用,用于组合
>=   大于等于
BETWEEN   在指定的两个值之间
IS NULL   为NULL值 (NULL表示无值的意思)
SELECT prod_name, prod_price
FROM Products
 ; --在二者之间
SELECT cust_name FROM CUSTOMERS
WHERE cust_email IS NULL; --显示其列cust_email为空的 cust_name

5.1逻辑操作符

and 满足二个子句

or   满足其中一个

SELECT prod_name, prod_price FROM Products
;--SQL(像多数语言一样)在处理OR操作符前,优先处理AND操作符
--等价于vend_id = 'DLL01' OR (vend_id = 'BRS01' AND prod_price >= 10)

所以如果想先OR 应该在or二个条件加括号

IN操作符 指定条件范围 (注in比or操作更快)

SELECT prod_name, prod_price FROM Products
WHERE vend_id IN ( 'DLL01', 'BRS01' ) ORDER BY prod_name;--显示包含了'DLL01', 'BRS01'的

NOT操作符 排除

SELECT prod_name FROM Products
WHERE NOT vend_id = 'DLL01' ORDER BY prod_name;--除去'DLL01' 的所有都显示出来

6.1 LIKE操作符

多个通配符%  任何字符出现任意次数 (注 Access需要使用*)  不匹配null

SELECT prod_id, prod_name FROM Products
WHERE prod_name LIKE 'Fish%';  --开头为Fish的

单个通配符_  匹配单个字符            (注 Access需要使用?)  不匹配null  语法和%一样

[]通配符  匹配一个字符,内容为方括号内的

SELECT cust_contact FROM Customers
WHERE cust_contact LIKE '[JM]%'  --匹配J或M开头的cust_contact

7.2计算字段

拼接字段

SELECT vend_name + ' (' + vend_country + ')' FROM Vendors ORDER BY vend_name;--拼接vend_name与end_country字段

RTRIM()删除右边的空格  LTRIM()删除左边的空格 trim()删除左右二边的空格

SELECT RTRIM(vend_name) + ' (' + RTRIM(vend_country) + ')' FROM Vendors ORDER BY vend_name;--删除右边的空格再合并

AS 显示别名

SELECT vend_name  AS vend_title FROM Vendors --用vend_title别名显示结果

执行算术运算

SELECT prod_id, quantity, item_price,
quantity*item_price AS expanded_price --把查询到的quantity与item_price字段的结果相乘用expanded_price显示
;

8.1函数

函数 说明   函数 说明
LEFT(字段名,2) 返回字符串左边的2个字符 相反 RIGHT(字段名,2) 返回字符串右边的2个字符
LOWER()
Access使用LCASE()
     将字符串转换为小写   UPPER()
Access使用UCASE()
将字符串转换为大写
LTRIM()      去掉字符串左边的空格   RTRIM() 去掉字符串右边的空格
Soundex() 返回字符串的SOUNDEX值
主要用于英语读法相似的(略过)
  length() 返回字符串的长度

日期处理函数

SELECT order_num,order_date FROM Orders
; --表示字段order_date的年份为2012年的
--DATEPART(M, order_date)如果是M则表示月份是5月,d为日,H为时,mm为分,ss为秒

数值处理函数

ABS() 绝对值 PI() 圆周率 SQRT() 平方根 EXP() 指数值
COS() 角度余弦 SIN() 角度正弦 TAN() 角度正切    

9.1聚集函数

AVG() 平均值 COUNT() 计数(共几行) MAX() 最大值 MIN() 最小值
SUM() 总计(和运算)            

9.3组合聚集函数

SELECT COUNT(*) AS num_items,
       MIN(prod_price) AS price_min,
       MAX(prod_price) AS price_max,
       AVG(prod_price) AS price_avg
FROM Products;

10.2分组与过滤

SELECT order_num, COUNT(*) AS items
FROM OrderItems
GROUP BY order_num     --这里按order_num分组
   --这里给分组过滤,显示分组大于3的
ORDER BY items, order_num;   --排序方式,可以理解为对结果的排序处理

11 使用子查询

先得到子句的结果再去查询 (注意嵌套子查询只能单列(多列将返回错误))

SELECT cust_name, cust_contact
FROM Customers
WHERE cust_id IN (SELECT cust_id
                  FROM Order
                  WHERE order_num IN (SELECT order_num
                                      FROM OrderItems
                                      WHERE prod_id = 'RGAN01'));

先得到父句的结果再去查询子句

SELECT cust_name,
       cust_state,
       (SELECT COUNT(*)
        FROM Orders
        WHERE Orders.cust_id = Customers.cust_id) AS orders --这里的子句用结果中的Customers.cust_id为条件去查询(只能返回一个)
FROM Customers
ORDER BY cust_name;

12 联结

SELECT vend_name, prod_name, prod_price
FROM Vendors, Products
WHERE Vendors.vend_id = Products.vend_id;  --内部相同的联结,不相同的不显示

多表联结,则使用and

SELECT cust_name, cust_contact FROM Customers, Orders, OrderItems
WHERE Customers.cust_id = Orders.cust_id AND OrderItems.order_num = Orders.order_num AND prod_id = 'RGAN01';

自联结

找Jim Jones的公司的所有记录

SELECT c1.cust_id, c1.cust_name, c1.cust_contact
FROM Customers AS c1, Customers AS c2
WHERE c1.cust_name = c2.cust_name   --找c1表内与c2结果列名cust_name一样的的记录
 AND c2.cust_contact = 'Jim Jones'; --先找到jim Jones那一行,得到c2表的一行

外连接

左联接 LEFT OUTER JOIN

SELECT Customers.cust_id, Orders.order_num
FROM Customers LEFT OUTER JOIN Orders ---以左边的表为基础显示结果
 ON Customers.cust_id = Orders.cust_id;

右联接 RIGHT OUTER JOIN

SELECT Customers.cust_id, Orders.order_num
FROM Customers RIGHT OUTER JOIN Orders --右边表为基础显示结果
 ON Orders.cust_id = Customers.cust_id;

全联接 FULL OUTER JOIN

SELECT Customers.cust_id, Orders.order_num
FROM Orders FULL OUTER JOIN Customers --显示比二个表为基础的结果
ON Orders.cust_id = Customers.cust_id;

左连接并分组计算

SELECT Customers.cust_id,
       COUNT(Orders.order_num) AS num_ord
FROM Customers LEFT OUTER JOIN Orders
 ON Customers.cust_id = Orders.cust_id
GROUP BY Customers.cust_id;

组合查询UNION (二个结果同一行会被自动取消) (合并结果,二个查询结果的字段要一致,类型能隐式转换)

SELECT cust_name, cust_contact, cust_email
FROM Customers
WHERE cust_state IN ('IL','IN','MI')
UNION -- 这里改成UNION ALL则显示二个查询的集合,不会自动取消同一行
SELECT cust_name, cust_contact, cust_email
FROM Customers
WHERE cust_name = 'Fun4All';

15 数据插入

插入检索出来的数据

INSERT INTO Customers
(cust_id,cust_contact,cust_email,cust_name,cust_address,cust_city,cust_state,cust_zip,cust_country)
SELECT --从CustNew检索出的结果插入到Customers表中,插入时主要为列的顺序,非字段名
 cust_id,cust_contact,cust_email,cust_name,cust_address,cust_city,cust_state,cust_zip,cust_country
FROM CustNew;

复制新表

SELECT * --所有列,如果只是部分,应指定列名
INTO CustCopy  --新的表名
FROM Customers;

16 更新数据

UPDATE Customers
SET cust_contact = 'Sam Roberts',
    cust_email = 'sam@toyland.com'  --也可以直接设置为null, cust_email = NULL
'; --更新时一定要注意过滤,不然所有行都会更新掉

删除数据  注!删除前最好使用select检索结果,看where是否有错

DELETE FROM Customers
';

17创建表

CREATE TABLE OrderItems
(
    order_num      INTEGER          NOT NULL,  --不能为空值,不允许NULL值
    order_item     INTEGER           NULL,   --表示可以为空值
    prod_id        )         NOT NULL,
    quantity       ,  --默认值为1
    item_price     ,2)     --省略NOT NULL时,默认可以为空l
);
GO
--判断非空的写法WHERE 字段 IS NULL
SET ANSI_NULLS ON
GO
--标识符可以由双引号分隔,文字必须由单引号分隔
SET QUOTED_IDENTIFIER ON
GO
--允许空值的Char(n)和binary(n)列填充到列长
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Pc_ADAccount]
(
) NOT NULL,
) NULL,
) NULL,
) NULL,
[F_PublicAccount] [bit] NULL,
) NULL,
--为多个键定义约束(PK_SYS_ADAccount为) asc升序NONCLUSTERED非聚集索引
CONSTRAINT [PK_Pc_ADAccount] PRIMARY KEY NONCLUSTERED
(
    [F_Id] ASC
)WITH (PAD_INDEX  = OFF,
STATISTICS_NORECOMPUTE  = OFF,
IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS  = ON,
ALLOW_PAGE_LOCKS  = ON
) ON [PRIMARY]
) ON [PRIMARY]

GETDATE()系统时间

慎用下面命令

添加一列

ALTER TABLE Vendors
)

移除一列

ALTER TABLE Vendors
DROP COLUMN vend_phone;

修改列类型

ALTER TABLE EmployeeInfo
ALTER COLUMN Employee_number NVARCHAR(Max)

修改列的字段名

exec sp_rename '表名.原列名','新列名','column';

删除表

DROP TABLE CustCopy;--可以使用关系规则防止意外删除

SQL Server用户使用sp_rename存储过程重命名表

18视图

CREATE VIEW CustomerEMailList AS  --创建视图,创建一个cust_email不为空的表,查询时和表格一样操作
SELECT cust_id, cust_name, cust_email
FROM Customers
WHERE cust_email IS NOT NULL;

19执行存储过程

EXECUTE AddNewProduct( 'JTS01', 'Stuffed Eiffel Tower',6.49,'Plush stuffed toy with the text La Tour Eiffel in red white and blue' );
--执行存储过程,其参数有多个

创建存储过程

)
ASSET NOCOUNT OFF -- 显示受影响的行数
DECLARE @order_num INTEGER  -- 为订单编号声明变量 在上面没有变量时,可自己定义变量
SELECT @order_num=MAX(order_num)-- 获取当前最高订单号
FROM Orders
SELECT @order_num=@order_num+1 -- 确定下一个订单号
INSERT INTO Orders(order_num, order_date, cust_id) -- 插入新的秩序
VALUES(@order_num, GETDATE(), @cust_id)
RETURN @order_num;-- 返回的订单号

存储过程的输写格式

create proc testpray
)
as
declare @_id int
 from test
insert into test(id,name)values(@_id,@prayname)

--下面是测试显示
declare @str int
 exec @str = testpray artre
select @str

20管理事务处理

相关知识点

注意:书本的实例测试时,部分有问题,这里请查询网上相关资料为准

事务管理

BEGIN TRAN  --开始事务
', 'Toys Emporium');
', 'Toys Emporium');
 Rollback tran;  --ERROR为SQL函数,出错时ERROR不为零,意在上面的操作中有错误时回滚事务
COMMIT TRAN --这是提交事务,可以理解为,之前BEGIN TRAN之后的一系列操作还没保存!在时才会保存到源数据里
select * from Customers

事务保存点

begin Tran;  --这是TRANSACTION的缩写 在begin Tran这后总有一个ROLLBACK Tran回滚事务或commit tran执行事务,
save tran test_1; --保存点test_1
';
save tran test_2;  --保存点test_2
';
ROLLBACK Tran test_1; --回滚至保存点test_2 ,
--commit tran;  --提交事务,事务的结束,如果没设置自动结束,事务会占用资源,无法查询
select * from CustNew;

21游标

游标很少用于ASP等 参考资料

DECLARE CustCursor CURSOR ----声明时未指定"local"或"global"关键字,系统默认游标是"global(全局)"的.
FOR SELECT * FROM Customers WHERE cust_email IS NULL
OPEN CustCursor  --在open时,执行查询,存储检索出的数据以供浏览和滚动.
FETCH NEXT FROM CustCursor --读取游标数据,其中的NEXT为下一行记录,详见附2,这里可以执行 单语句运行
CLOSE CustCursor; --关闭游标
Deallocate CustCursor; --释放游标
/*
附1:标准游标:Declare MyCursor Cursor For Select * From Master_Goods
    只读游标:Declare MyCusror Cursor For Select * From Master_Goods For Read Only
    可更新游标:Declare MyCusror Cursor For Select * From Master_Goods For UpDate

附2:Next表示返回结果集中当前行的下一行记录,如果第一次读取则返回第一行。默认的读取选项为Next
    Prior表示返回结果集中当前行的前一行记录,如果第一次读取则没有行返回,并且把游标置于第一行之前。
    First表示返回结果集中的第一行,并且将其作为当前行。
    Last表示返回结果集中的最后一行,并且将其作为当前行。
    Absolute n 如果n为正数,则返回从游标头开始的第n行,并且返回行变成新的当前行。如果n为负,则返回从游标末尾开始的第n行,并且返回行为新的当前行,如果n为0,则返回当前行。
    Relative n 如果n为正数,则返回从当前行开始的第n行,如果n为负,则返回从当前行之前的第n行,如果为0,则返回当前行。
*/

22约束

CREATE TABLE Vendors (
  vend_id         )       NOT NULL    PRIMARY KEY, --Primary key设置为主键
  vend_name       )       NOT NULL,
  )
ALTER TABLE Vendors  --修改列
ADD CONSTRAINT PRIMARY KEY (vend_id);--改为主键 使用的是Constraintd 强迫

外键

CREATE TABLE Orders
(
    order_num     INTEGER     NOT NULL PRIMARY KEY,
    order_date    DATETIME    NOT NULL,
    cust_id       )    NOT NULL REFERENCES Customers(cust_id) --定义外键为Customers的cust_id字段
);

检查约束

CREATE TABLE OrderItems
(
    order_num     INTEGER     NOT NULL,
    order_item    INTEGER     NOT NULL,
    prod_id       )    NOT NULL,
    quantity      ), --约束其列值必须大于0
    item_price    MONEY       NOT NULL
);
ADD CONSTRAINT CHECK (gender LIKE '[MF]') --检查列中只包含M或F

索引

CREATE INDEX prod_name_ind --建立索引
ON PRODUCTS (prod_name); --建立索引的表下的列

触发器

CREATE TRIGGER customer_state --建立索引
ON Customers --表名Customers
FOR INSERT, UPDATE  --插入与修改操作
AS
UPDATE Customers
SET cust_state = Upper(cust_state) --cust_state列
WHERE Customers.cust_id = inserted.cust_id; --插入的数据表等于源数据的cust_id列

以下为示例用数据表

-----------------------------------------------------------
-- Sams Teach Yourself SQL in 10 Minutes
-- http://forta.com/books/0672336073/
-- Example table creation scripts for Microsoft SQL Server.
-----------------------------------------------------------

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

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

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

------------------------
-- Create Products table
------------------------
CREATE TABLE Products
(
  prod_id    )      NOT NULL ,
  vend_id    )      NOT NULL ,
  prod_name  )     NOT NULL ,
  prod_price ,2)  NOT NULL ,
  prod_desc  ) NULL
);

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

----------------------
-- Define primary keys
----------------------
ALTER TABLE Customers WITH NOCHECK ADD CONSTRAINT PK_Customers PRIMARY KEY CLUSTERED (cust_id);
ALTER TABLE OrderItems WITH NOCHECK ADD CONSTRAINT PK_OrderItems PRIMARY KEY CLUSTERED (order_num, order_item);
ALTER TABLE Orders WITH NOCHECK ADD CONSTRAINT PK_Orders PRIMARY KEY CLUSTERED (order_num);
ALTER TABLE Products WITH NOCHECK ADD CONSTRAINT PK_Products PRIMARY KEY CLUSTERED (prod_id);
ALTER TABLE Vendors WITH NOCHECK ADD CONSTRAINT PK_Vendors PRIMARY KEY CLUSTERED (vend_id);

----------------------
-- Define foreign keys
----------------------
ALTER TABLE OrderItems ADD
CONSTRAINT FK_OrderItems_Orders FOREIGN KEY (order_num) REFERENCES Orders (order_num),
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);

创建表

-------------------------------------------------------------
-- Sams Teach Yourself SQL in 10 Minutes
-- http://forta.com/books/0672336073/
-- Example table population scripts for Microsoft SQL Server.
-------------------------------------------------------------

---------------------------
-- Populate Customers table
---------------------------
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
', '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)
', 'USA', 'Michelle Green');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
', '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)
', '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)
', 'USA', 'Kim Howard');

-------------------------
-- Populate Vendors table
-------------------------
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
', 'USA');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
', 'USA');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
', 'USA');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
', '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)
', '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)
, ');
INSERT INTO Orders(order_num, order_date, cust_id)
, ');
INSERT INTO Orders(order_num, order_date, cust_id)
, ');
INSERT INTO Orders(order_num, order_date, cust_id)
, ');
INSERT INTO Orders(order_num, order_date, cust_id)
, ');

----------------------------
-- Populate OrderItems table
----------------------------
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 1, , 5.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 2, , 10.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 1, , 5.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 2, , 8.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 3, , 11.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 1, , 11.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 2, , 2.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 3, , 2.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 4, , 2.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 5, , 4.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 1, , 4.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 2, , 11.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 3, , 3.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 4, , 3.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 5, , 3.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 1, , 2.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 2, , 2.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
, 3, , 2.49);

插入数据

SQL必知必会学习笔记的更多相关文章

  1. 《SQL必知必会》学习笔记二)

    <SQL必知必会>学习笔记(二) 咱们接着上一篇的内容继续.这一篇主要回顾子查询,联合查询,复制表这三类内容. 上一部分基本上都是简单的Select查询,即从单个数据库表中检索数据的单条语 ...

  2. 《SQL必知必会》学习笔记整理

    简介 本笔记目前已包含 <SQL必知必会>中的所有章节. 我在整理笔记时所考虑的是:在笔记记完后,当我需要查找某个知识点时,不需要到书中去找,只需查看笔记即可找到相关知识点.因此在整理笔记 ...

  3. 《SQL必知必会》学习笔记(一)

    这两天看了<SQL必知必会>第四版这本书,并照着书上做了不少实验,也对以前的概念有得新的认识,也发现以前自己有得地方理解错了.我采用的数据库是SQL Server2012.数据库中有一张比 ...

  4. 读书笔记汇总 - SQL必知必会(第4版)

    本系列记录并分享学习SQL的过程,主要内容为SQL的基础概念及练习过程. 书目信息 中文名:<SQL必知必会(第4版)> 英文名:<Sams Teach Yourself SQL i ...

  5. 【SQL必知必会笔记(1)】数据库基础、SQL、MySQL8.0.16下数据库、表的创建及数据插入

    文章目录 1.数据库基础 1.1 数据库(database) 1.2 表(table) 1.3 列和数据类型 1.4 行 1.5 主键 2.什么是SQL 3.创建后续练习所需数据库.表(MySQL8. ...

  6. 读书笔记--SQL必知必会18--视图

    读书笔记--SQL必知必会18--视图 18.1 视图 视图是虚拟的表,只包含使用时动态检索数据的查询. 也就是说作为视图,它不包含任何列和数据,包含的是一个查询. 18.1.1 为什么使用视图 重用 ...

  7. SQL语法语句总结(《SQL必知必会》读书笔记)

    一.SQL语句语法 ALTER TABLE ALTER TABLE 用来更新已存在表的结构. ALTER TABLE tablename (ADD|DROP column datatype [NULL ...

  8. 学习《SQL必知必会(第4版)》中文PDF+英文PDF+代码++福达BenForta(作者)

    不管是数据分析还是Web程序开发,都会接触到数据库,SQL语法简洁,使用方式灵活,功能强大,已经成为当今程序员不可或缺的技能. 推荐学习<SQL必知必会(第4版)>,内容丰富,文字简洁明快 ...

  9. 《MySQL必知必会》学习笔记——前言

    前言 MySQL已经成为世界上最受欢迎的数据库管理系统之一.无论是用在小型开发项目上,还是用来构建那些声名显赫的网站,MySQL都证明了自己是个稳定.可靠.快速.可信的系统,足以胜任任何数据存储业务的 ...

  10. 【SQL必知必会笔记(3)】SELECT语句的WHERE子句数据过滤操作

    上个笔记主要介绍了利用SELECT语句检索单个/多个/所有列,并利用DISTINCT关键字检索具有唯一性的值.利用LIMIT/OFFSET子句限制结果:以及利用ORDER BY子句排序检索出的数据,主 ...

随机推荐

  1. Maven安装本地jar包至本地repository

    1.安装jar包 Maven 安装 JAR 包的命令是:   mvn install:install-file -Dfile=jar包的位置 -DgroupId=上面的groupId -Dartifa ...

  2. isset、empty 误区

    isset()  常用来判定变量是否存在  但是当变量赋值为NUll时候,返回值一样是FALSE  而实际上变量是存在的,与实际情况不符,判定错误. empty() 用来判定变量或者类的属性值是否为等 ...

  3. 刚性方程 Stiff equation

    In mathematics, a stiff equation is a differential equation for which certain numerical methods for ...

  4. Note:目录2

    ylbtech-Note:目录2 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylbtech ...

  5. sqlalchemy.exc.IntegrityError: (mysql.connector.errors.IntegrityError) 1062 (23000): Duplicate entry '1' for key 'PRIMARY'

    排错: 看到 Duplicate entry '1' for key 'PRIMARY'是主键错误 看一看自己添加的数据id是1 再查询一下数据库中的表,发现id=1的记录已经存在了 所以在代码中让i ...

  6. iview 表格 某一列中设置radio

    在iview 表格 某一列中设置radio,说白了还是要在render中添加,方法为: { title: '业务参数设置', // key: 'pyCode', align: 'center', re ...

  7. webpack的code spliting与chunks

    webpack的code spliting与chunks :https://blog.csdn.net/liuqi332922337/article/details/53020992

  8. kmp(前中后最长相同长度)

    http://acm.hdu.edu.cn/showproblem.php?pid=4763 Theme Section Time Limit: 2000/1000 MS (Java/Others)  ...

  9. HTTP中ip地址伪造的问题以及解决办法

    在真实环境下,php获取客户端ip地址的方法通常有以下几种: (1):通过$_SERVER[ "HTTP_CLIENT_IP" ] (2):通过$_SERVER[ "HT ...

  10. redis 不可重入分布式锁(setNx()和getset()方法实现)

    通常如果在单机环境,使用synchronized或juc ReentrantLock 实现锁机制,但如果是分布式系统,则需要借助第三方工具实现,比如redis.zookeeper等.redis为单进程 ...