-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAS4_1.sql
48 lines (39 loc) · 1.02 KB
/
AS4_1.sql
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
--1.a
INSERT INTO Region VALUES(5, 'Middle Earth')
--1.b
INSERT INTO Territories VALUES(11111,'Gondor', 5)
--1.c
INSERT INTO Employees(EmployeeID, LastName, FirstName, Territory)
VALUES(10,'King', 'Aragorn', 'Gondor')
--2.
BEGIN TRAN
UPDATE Territories SET TerritoryDescription='Arnor'
WHERE TerritoryDescription='Gondor'
--3.
BEGIN TRAN
DELETE FROM Region
WHERE RegionDescription='Middle Earth'
ROLLBACK
BEGIN TRAN
SELECT * FROM Region WITH(HOLDLOCK)
SELECT * FROM Employees WITH(HOLDLOCK)
SELECT * FROM Territories WITH(HOLDLOCK)
COMMIT TRAN
--4.
CREATE VIEW view_product_order_chen AS
SELECT p.ProductName, COUNT(od.Quantity) 'Quantity' from Products p
INNER JOIN [Order Details] od
on p.ProductID = od.ProductID
GROUP BY p.ProductName
--5.
ALTER PROC sp_product_order_quantity_chen
(@id int,
@total int out)
AS
BEGIN
SELECT @id = view_product_quantity_order_Yang.ProductID,
@total = view_product_quantity_order_Yang.QuantityCount
FROM view_product_quantity_order_chen
where view_product_quantity_order_chen.ProductID = @id
END
--6.