Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.14 KB | None | 0 0
  1.  
  2. create database databejz
  3. use databejz
  4.  
  5. create table proizvodi
  6. (
  7. ProizvodID int not null identity(1,1) constraint PK_ProizvodID  primary key,
  8.  Sifra nvarchar (25) not null constraint UQ_sifra unique,
  9.     Naziv nvarchar (50) not null,
  10.     Kategorija nvarchar (50) null,
  11.  Podkategorija  nvarchar (50) null,
  12.  Boja   nvarchar (15) not null,
  13.  Cijena decimal not null,
  14.  StanjeZaliha   int not null
  15. );
  16.  
  17. create table prodaja
  18. (
  19. ProdajaID int not null identity(1,1) constraint PK_ProdajaID primary key,  
  20.  ProizvodID int not null constraint FK_Proizvodi_ProizvodID foreign key references proizvodi(ProizvodID),  
  21.  Godina  int not null,  
  22. Mjesec int not null,   
  23.  UkupnoProdano int not null,
  24. UkupnoPopust decimal not null,
  25. UkupnoIznos decimal not null
  26.  
  27.  
  28. );
  29.  
  30. insert into proizvodi
  31. (Sifra,Naziv,Kategorija,Podkategorija,Boja,Cijena,StanjeZaliha)
  32. values('ssds','sako',null,null,'roza',34,15)
  33.  
  34. insert into prodaja
  35. (ProizvodID,Godina,Mjesec, UkupnoProdano,UkupnoPopust,UkupnoIznos)
  36. values(1,2014,3,33, 0.9, 30),(1,2014,7,33, 0.9, 30),(1,2015,3,33, 0.9, 30)
  37. --------------------------------------
  38. set identity_insert proizvodi ON
  39. insert into proizvodi
  40. (ProizvodID,Sifra,Naziv,Kategorija,Podkategorija,Boja,Cijena,StanjeZaliha)
  41. select distinct p.ProductID,p.ProductNumber,p.Name, pc.Name,psc.Name, p.Color,p.ListPrice,pi.Quantity
  42. from AdventureWorks2017.Production.Product as p
  43. inner join AdventureWorks2017.Production.ProductSubcategory as psc on psc.ProductSubcategoryID= p.ProductSubcategoryID
  44. inner join AdventureWorks2017.Production.ProductCategory as pc on pc.ProductCategoryID= psc.ProductCategoryID
  45. inner join AdventureWorks2017.Production.ProductInventory as pi on pi.ProductID= p.ProductID
  46. inner join AdventureWorks2017.Sales.SalesOrderDetail as sod on sod.ProductID= p.ProductID
  47. inner join AdventureWorks2017.Sales.SalesOrderHeader as soh on soh.SalesOrderID= sod.SalesOrderID
  48. inner join AdventureWorks2017.Sales.SalesTerritory as st on st.TerritoryID= soh.TerritoryID
  49. inner join AdventureWorks2017.Production.Location as l on l.LocationID= pi.LocationID
  50. where st.[Group] ='Europe'
  51. order by    p.ProductID
  52. set identity_insert proizvodi oFF
  53.  
  54. select* from proizvodi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement