Advertisement
Guest User

SQL

a guest
Dec 6th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. SELECT * FROM Nugget
  2. SELECT * FROM Employee
  3. SELECT * FROM [dbo].[Transaction]
  4. SELECT * FROM TransactionDetail
  5. SELECT * FROM LoginLog
  6.  
  7. SELECT UserName FROM LoginLog WHERE [EmployeeID] = 'EMP004'
  8. SELECT EmployeeID FROM Employee WHERE UserName = 'adit'
  9.  
  10. SELECT * FROM [dbo].[TransactionDetail]
  11. INSERT INTO [dbo].[Transaction] VALUES('T003','EMP001','2015-09-17','17000')
  12.  
  13. drop table [dbo].[Transaction]
  14.  
  15. truncate table dbo.TransactionDetail
  16. SELECT Nugget.name FROM Nugget WHERE ID = 'N001'
  17.  
  18. SELECT UserName FROM LoginLog WHERE [EmployeeID] = 'EMP001'
  19.  
  20. SELECT * FROM Employee WHERE Employee.Position = 'Admin'
  21.  
  22. UPDATE Nugget SET Name = 'Chicken Nugget', Description = 'Chicken', Stock = '30', Price = '20000' WHERE ID = 'N001'
  23. UPDATE Employee SET Employee.Status = 'Active' WHERE EmployeeID = 'EMP006'
  24. UPDATE Employee SET Employee.Status = 'Non-active' WHERE EmployeeID = 'EMP002'
  25. UPDATE Employee SET UserName = 'rico', Password = 'rico123', FullName = 'ricooo', Gender = 'Male', Position = 'Cashier', Status = 'Active' WHERE EmployeeID = 'EMP002'
  26.  
  27. SELECT TOP 1 ID FROM NUGGET ORDER BY ID DESC
  28. SELECT TOP 1 TransactionID FROM [dbo].[Transaction] ORDER BY TransactionID DESC
  29. SELECT TOP 1 EmployeeID FROM Employee ORDER BY EmployeeID DESC
  30.  
  31. SELECT TOP 1 dbo.LoginLog.EmployeeID FROM dbo.LoginLog ORDER BY dbo.LoginLog.EmployeeID DESC
  32.  
  33. DELETE FROM Nugget WHERE ID = 'N001'
  34. DELETE FROM Employee WHERE EmployeeID = 'EMP002'
  35. DELETE FROM [dbo].[Transaction] WHERE TransactionID = 'T003'
  36. DELETE FROM [dbo].[TransactionDetail] WHERE TransactionID = 'T003'
  37. DELETE FROM LoginLog WHERE UserName = 'asd'
  38.  
  39. INSERT Nugget VALUES ('N004', 'Tofu Nugget', 'Tofu', '47', '17000')
  40. INSERT Employee VALUES ('EMP001', 'adit', 'adit123', 'adityaa', 'Male', 'Admin', 'Active')
  41. INSERT Employee VALUES ('EMP002', 'rico', 'rico123', 'ricooo', 'Male', 'Cashier', 'Non-active')
  42. INSERT Employee VALUES ('EMP003', 'ica', 'ica123', 'icaaaa', 'Female', 'Cashier', 'Active')
  43. INSERT Employee VALUES ('EMP004', 'asd', 'asd123', 'asdasd', 'Male', 'Cashier', 'Active')
  44. INSERT [dbo].[Transaction] VALUES ('T002', 'EMP001', '2015/09/17', '17000')
  45. INSERT TransactionDetail VALUES ('T002', 'N001', '1')
  46. INSERT LoginLog VALUES ('EMP001', 'adit', '17-7-2017')
  47.  
  48. SELECT * FROM [dbo].[Transaction] INNER JOIN TransactionDetail ON [dbo].[Transaction].TransactionID = TransactionDetail.TransactionID
  49.  
  50. SELECT
  51. [dbo].[Transaction].TransactionID AS TransactionID,
  52. [dbo].[Transaction].GrandTotal as GrandTotal,
  53. TransactionDetail.NuggetID as NuggetID,
  54. TransactionDetail.Quantity as Qty
  55. FROM
  56. [dbo].[Transaction]
  57. INNER JOIN TransactionDetail ON [dbo].[Transaction].TransactionID=TransactionDetail.TransactionID
  58.  
  59. SELECT
  60. [dbo].[Transaction].TransactionID AS TransactionID,
  61. Nugget.ID as NuggetID,
  62. Nugget.name AS NuggetName,
  63. Nugget.price AS UnitPrice,
  64. TransactionDetail.Quantity as Qty,
  65. [dbo].[Transaction].GrandTotal as GrandTotal
  66. FROM [dbo].[Transaction]
  67. INNER JOIN TransactionDetail ON [dbo].[Transaction].TransactionID=TransactionDetail.TransactionID
  68. INNER JOIN Nugget ON TransactionDetail.NuggetID = Nugget.ID WHERE ID = 'N001'
  69.  
  70. create trigger Kurang_Stock
  71. on [dbo].[TransactionDetail]
  72. after insert
  73. as
  74. begin
  75. declare @Qty int
  76. select @Qty = Quantity from inserted
  77. update [dbo].[Nugget] set stock = stock - @Qty
  78. where ID in (select NuggetID from inserted)
  79. end
  80.  
  81. select * from [dbo].[Nugget]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement