Monday, October 31, 2016

SQl 1

Use Bakery Select * from Person; Select PersonLastname, PersonFirstname, PersonEmail From Person; Select PersonLastname, PersonFirstname, PersonEmail From Person Where PersonEmail is not null Order by PersonLastName;

Here is the SQL we did in class


Select PersonLastName, PersonFirstname, PersonEmail
From Person
Where PersonFirstName = 'Tabitha';

Select PersonLastName, PersonFirstname, PersonEmail
From Person
Where PersonFirstName Like 'T%';

Select * from Product

Select * from Product where productprice > 3
Select * from Product where productprice = 3
Select * from Product where productprice >= 3
Select * from Product where productprice between 2.5 and 3.5
Select * from Product where productprice >= 2.5 
and ProductPrice <= 3.5

Select * from Sale where SaleDate >= '10/31/2016'
Select * from saleDetail

Select Sale.SaleKey,SaleDate,PersonLastName, Employeekey, ProductName, 
SaleDetailPriceCharged, SaleDetailQuantity,SaleDetailDiscount,
SaleDetailSaleTaxPercent,SaleDetailEatInTax
From Person
inner join Sale
on Person.PersonKey=Sale.CustomerKey
inner Join SaleDetail
on Sale.SaleKey=SaleDetail.SaleKey
inner Join Product
on Product.ProductKey=SaleDetail.ProductKey
Where Sale.SaleKey=1

Select * from Product

Insert into Sale (SaleDate, CustomerKey, EmployeeKey)
Values(GetDate(),5,2)
Insert into SaleDetail(SaleKey, 
ProductKey, SaleDetailPriceCharged, 
SaleDetailQuantity, SaleDetailDiscount, 
SaleDetailSaleTaxPercent, 
SaleDetailEatInTax)
Values(ident_current('Sale'),3,2.25,1,0.0,0.09,0),
(ident_current('Sale'),6,1.25,1,0.0,0.9,0)

Select * from SaleDetail 

Select * from Person

Begin tran

Update Person Set PersonLastName='Smith'
Where PersonKey = 2

rollback tran

Commit tran

No comments:

Post a Comment