Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. USE [master]
  2. GO
  3. CREATE LOGIN [ZAL] WITH PASSWORD=N'12345', DEFAULT_DATABASE=[Northwind], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
  4. GO
  5. USE [Northwind]
  6. GO
  7. CREATE USER [ZAL] FOR LOGIN [ZAL]
  8. GO
  9. GRANT INSERT, SELECT ON [dbo].[CATEGORIES] to [ZAL]
  10. go
  11. GRANT INSERT, SELECT ON [dbo].[Products] to [ZAL]
  12. go
  13. GRANT INSERT, SELECT ON [dbo].[ORDER DETAILS] to [ZAL]
  14.  
  15. --1
  16. sp_addlinkedserver @server='OrclDB'
  17. ,@srvproduct='Oracle'
  18. ,@provider='OraOLEDB.Oracle'
  19. ,@datasrc='hw12'
  20.  
  21. sp_addlinkedsrvlogin @rmtsrvname='OrclDB'
  22. ,@useself='FALSE'
  23. ,@locallogin='ZAL'
  24. ,@rmtuser='pd202115'
  25. ,@rmtpassword='12345'
  26.  
  27. --2
  28.  
  29. --z oracle
  30. SELECT * FROM OPENQUERY (OrclDB, 'select OrderID, max(UnitPrice*Quantity) as najwyzsza from NORTHWIND.[ORDER DETAILS] where rownum = 1
  31. group by OrderID
  32. order by najwyzsza desc');
  33.  
  34. --lokalnie
  35. select top 1 OrderID, max(UnitPrice*Quantity) as najwyzsza from [Order Details]
  36. group by OrderID
  37. order by najwyzsza desc
  38.  
  39.  
  40. --3
  41. select * from products
  42. select * from Categories
  43.  
  44. --testowa procedura (lokalnie)
  45. create procedure PROC2
  46. (
  47. @Kategoria nvarchar(50)
  48. )as
  49. (select c.CategoryName, count(p.CategoryID) as [liczba produktow] from Products p
  50. join Categories c on c.CategoryID=p.CategoryID
  51. where c.CategoryName like @Kategoria
  52. group by c.CategoryName
  53. )
  54.  
  55. exec PROC2 'Beverages'
  56.  
  57. --procedura z openrowset
  58. create procedure PROC2
  59. (
  60. @Kategoria nvarchar(50)
  61. )as
  62. (select c.CategoryName, count(p.CategoryID) as [liczba produktow] from Products p
  63. inner join OPENROWSET('OraOLEDB.Oracle', 'hw12';'HR';'hr',
  64. 'SELECT xxx.CategoryName, xxx.CategoryID
  65. FROM Northwind.dbo.Categories xxx') as c on c.CategoryID=p.CategoryID
  66. where c.CategoryName like @Kategoria
  67. group by c.CategoryName
  68. )
  69.  
  70. exec PROC2 'Beverages'
  71.  
  72.  
  73. --5
  74.  
  75. --lokalnie
  76. select ProductName, UnitPrice from Products
  77. group by ProductName, UnitPrice
  78. having UnitPrice>(select avg(UnitPrice) from Products)
  79.  
  80.  
  81.  
  82.  
  83. --Z
  84. Select *
  85. FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','C:\Folder\Northwind.mdb';'admin';'',
  86. 'SELECT xx.NazwaProduktu as ProductName xx.CenaJednostkowa as UnitPrice
  87. FROM Northwind.dbo.Produkty xx') p
  88. group by p.ProductName, p.UnitPrice
  89. having p.UnitPrice>(select avg(UnitPrice) from Products)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement