SQL Server CC
SQL Server CC
SQL Server CC
Bike Stores-DRL
SELECT TOP 1 B.brand_name AS Brand_name From Brands B
Join Products P ON B.brand_id=P.brand_id
Order BY P.list_Price desc
go
Bike stores-procedure
create proc usp_MaxNoOfProducts
as
begin
select b.brand_name as Brand_Name,c.category_name as Category_Name,p.product_name as
Product_Name
from Brands b,Categories c,Products p
where p.brand_id in
(select p.brand_id,count(p.brand_id)
from Produts p
group by p.brand_id
order by count(p.brand_id) desc
limit 1)
end
GO
Clothing store-DDL
create table Customers(
CustomerId int primary key,
FirstName varchar(20) ,
SurName varchar(20),
CustomerState varchar(20)
)
go
create table Clothing (
ItemCode bigint primary key,
Description varchar(100),
RetailPrice decimal(6,2),
Discount decimal(5,2)
)
go
create table Transactions(
TransactionID int primary key,
TransactionDate datetime,
CustomerId int ,
ItemCode bigint
)
go
alter table Clothing
add unique (Description)
go
alter table Transactions
add foreign key(CustomerId) references Customers(CustomerId)
go
alter table Transactions
add foreign key(ItemCode) references Clothing(ItemCode)
go
Clothing store-DRL
select FirstName+","+SurName as CustomerName
from Customers
where CustomerId in
(select CustomerId from(select Customers.CustomerId, count(Customers.CustomerId) count
from Customers
join Transactions
on Customers.CustomerId= Transactions.CustomerId
group by Customers.CustomerId) a
where a.count>1)
go
Clothing store-procedure
go
Lodging house-DDL
create table rate(room_type_id varchar(6) not null ,occupancy int not null,amount
decimal(10,2) default 0)
GO
Lodging house-Procedure
Pet clinic-DDL
CREATE TABLE PetOwner(
OwnerId int PRIMARY KEY,
Name char(50), Surname char(50),
StreetAddress char(100),City char(100),
State char(10),ZipCode int)
GO
CREATE TABLE Pet(
PetId char(10) PRIMARY KEY,
Name char(20),
Kind char(10),Gender char(6), Age int, OwnerId int)
GO
CREATE TABLE ProcedureHistory(
PetId char(10),ProcedureDate date, ProcedureType char(50),Description char(100))
GO
ALTER TABLE PetOwner
ADD CONSTRAINT state_michi
DEFAULT 'Michigan' FOR state
GO
ALTER TABLE Pet
ADD CONSTRAINT fh foreign KEY(OwnerId) REFERENCES
PetOwner(OwnerId)
GO
ALTER TABLE ProcedureHistory
ADD CONSTRAINT fh1 FOREIGN KEY(PetId) REFERENCES Pet(PetId)
GO
Pet clinic-DRL
select a.Name as[Pet Name],a.kind,b.Name as[Owner Name]
from Pet a join PetOwner b on a.OwnerId=b.OwnerId
ORDER BY a.Name ASC
Go
select
a.PetId as petid,
a.Name as NAME,
a.kind as kind,
a.Gender as gender
from Pet a join ProcedureHistory b on a.PetId=b.PetId
where 1=(select MONTH(b.ProcedureDate))
order by a.PetId asc
Go
Pet clinic-procedure
create proc usp_PetProcedureDetais(@ProcedureType varchar(255))
select p.PetID as petid,p.Name as [Pet Name],o.Name as [Owner Name],h.Description as
description
FROM Pet p join PetOwner o on p.OwnerID=o.OwnerID join ProcedureHistory h on
p.PetID=h.PetID
where h.ProcedureType=@ProcedureType
end
Go
go