0% found this document useful (0 votes)
50 views

Database Scripts

The document contains the database schema scripts for several tables including sex, city, category, author, status, book, address, book_author, users, and TBorrow. It also includes stored procedures for retrieving data from these tables.

Uploaded by

Ozan Goylusun
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Database Scripts

The document contains the database schema scripts for several tables including sex, city, category, author, status, book, address, book_author, users, and TBorrow. It also includes stored procedures for retrieving data from these tables.

Uploaded by

Ozan Goylusun
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 10

Cneyt Hocam Merhabalar

Sunum bitiminde sorduumda sanrsam veritaban kodlarn da istemitiniz,


emin deilim. Ayrca, onlar rapora ilave etmek istemedik; nk
raporu gereksiz iireceini dndk ve o yzden burada paylatk.
Umarm beenirsiniz.
SE [library]
GO
/****** Object: Table [dbo].[sex] Script Date: 05/19/2014 20:04:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[sex](
[Id] [int] IDENTITY(1,1) NOT NULL,
[sex] [nvarchar](50) NULL,
CONSTRAINT [PK_sex] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object: Table [dbo].[city] Script Date: 05/19/2014 20:04:52 ******/


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[city](
[cityID] [int] IDENTITY(1,1) NOT NULL,
[CityName] [nchar](10) NULL,
CONSTRAINT [PK_city] PRIMARY KEY CLUSTERED
(
[cityID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

/****** Object: Table [dbo].[Category] Script Date: 05/19/2014 20:04:52


******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Category](
[CategoryId] [int] IDENTITY(1,1) NOT NULL,
[CategoryName] [nvarchar](50) NULL,
CONSTRAINT [PK_Category] PRIMARY KEY CLUSTERED
(
[CategoryId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object: Table [dbo].[Author] Script Date: 05/19/2014 20:04:52


******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Author](
[AuthorId] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[LastName] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_Author] PRIMARY KEY CLUSTERED
(
[AuthorId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object: Table [dbo].[Status]


******/

Script Date: 05/19/2014 20:04:52

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Status](
[statuID] [int] IDENTITY(1,1) NOT NULL,
[Status] [nvarchar](50) NULL,
CONSTRAINT [PK_Status] PRIMARY KEY CLUSTERED
(
[statuID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object: Table [dbo].[Book] Script Date: 05/19/2014 20:04:52


******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Book](
[BookId] [int] IDENTITY(1,1) NOT NULL,
[Title] [nvarchar](250) NULL,
[ISBN] [nvarchar](50) NULL,
[PublishDate] [date] NULL,
[StatusId] [int] NULL,
[CategoryId] [int] NULL,
[Place] [nvarchar](250) NULL,
[PlaceInLibrary] [nvarchar](50) NULL,
[Date] [date] NULL,
[Photo] [nvarchar](50) NULL,
CONSTRAINT [PK_Book] PRIMARY KEY CLUSTERED
(
[BookId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object: Table [dbo].[Address]

Script Date: 05/19/2014 20:04:52

******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Address](
[AddressId] [int] IDENTITY(1,1) NOT NULL,
[Adress] [nvarchar](250) NULL,
[CityId] [int] NULL,
CONSTRAINT [PK_Address] PRIMARY KEY CLUSTERED
(
[AddressId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object: Table [dbo].[book_Author] Script Date: 05/19/2014


20:04:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[book_Author](
[id] [int] IDENTITY(1,1) NOT NULL,
[bookId] [int] NULL,
[authorId] [int] NULL,
CONSTRAINT [PK_book_Author] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object: StoredProcedure [dbo].[sp_City]


20:04:50 ******/
SET ANSI_NULLS ON
GO

Script Date: 05/19/2014

SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[sp_City]
as begin
select l.adress,s.cityName from Address l
inner join city s on l.cityId=s.cityID
end
GO

/****** Object: Table [dbo].[Users] Script Date: 05/19/2014 20:04:52


******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Users](
[UserId] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL,
[LastName] [nvarchar](50) NULL,
[SexId] [int] NULL,
[Phone] [nvarchar](50) NULL,
[Email] [nvarchar](50) NULL,
[Tc] [nvarchar](50) NULL,
[AddressId] [int] NULL,
CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED
(
[UserId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object: StoredProcedure [dbo].[sp_User]


20:04:50 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[sp_User]
as begin

Script Date: 05/19/2014

select u.Name,u.LastName,u.Email,u.Phone,a.Adress,c.CityName,s.sex
from Users u
inner join sex s on s.Id=u.SexId
inner join Address a on a.AddressId=u.AddressId
inner join city c on c.cityID=a.CityId
end
GO

/****** Object: StoredProcedure [dbo].[sp_Sex] Script Date: 05/19/2014


20:04:50 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[sp_Sex]
as begin
select l.name,l.LastName,s.Sex,l.Email from users l
inner join sex s on l.sexId=s.Id
end
GO

/****** Object: Table [dbo].[TBorrow] Script Date: 05/19/2014 20:04:52


******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TBorrow](
[BorrowId] [int] IDENTITY(1,1) NOT NULL,
[UserId] [int] NULL,
[BookId] [int] NULL,
[BorrowDate] [nvarchar](50) NULL,
[ReturnDate] [nvarchar](50) NULL,
CONSTRAINT [PK_brrow] PRIMARY KEY CLUSTERED
(
[BorrowId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

/****** Object: View [dbo].[vw_sp_book_Author] Script Date: 05/19/2014


20:04:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view [dbo].[vw_sp_book_Author]
as
select
b.BookId,b.Title,a.Name,a.LastName,b.ISBN,b.PublishDate,s.Status,c.Catego
ryName,b.Place,b.PlaceInLibrary,b.Date,b.Photo from book_author ba
inner join Book b on b.BookId=ba.bookId
inner join Author a on a.AuthorId=ba.authorId
inner join Status s on s.statuID=b.StatusId
inner join Category c on c.CategoryId=b.CategoryId
GO

/****** Object: StoredProcedure [dbo].[sp_book_Author] Script Date:


05/19/2014 20:04:50 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[sp_book_Author]
as begin
select
b.BookId,b.Title,a.Name,a.LastName,b.ISBN,b.PublishDate,s.Status,c.Catego
ryName,b.Place,b.PlaceInLibrary,b.Date,b.Photo from book_author ba
inner join Book b on b.BookId=ba.bookId
inner join Author a on a.AuthorId=ba.authorId
inner join Status s on s.statuID=b.StatusId
inner join Category c on c.CategoryId=b.CategoryId
end
GO

/****** Object: StoredProcedure [dbo].[sp_Borrow]

Script Date:

05/19/2014 20:04:50 ******/


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[sp_Borrow]
as begin
select b.borrowId,b.UserId,bk.Title,s.Status,b.borrowdate,b.returndate from
TBorrow b
inner join Book bk on bk.BookId=b.BookId
inner join Status s on s.statuID=bk.StatusId
end
GO

/****** Object: ForeignKey [FK_Address_Address] Script Date:


05/19/2014 20:04:52 ******/
ALTER TABLE [dbo].[Address] WITH CHECK ADD CONSTRAINT
[FK_Address_Address] FOREIGN KEY([AddressId])
REFERENCES [dbo].[Address] ([AddressId])
GO
ALTER TABLE [dbo].[Address] CHECK CONSTRAINT [FK_Address_Address]
GO

/****** Object: ForeignKey [FK_Address_city] Script Date: 05/19/2014


20:04:52 ******/
ALTER TABLE [dbo].[Address] WITH CHECK ADD CONSTRAINT
[FK_Address_city] FOREIGN KEY([CityId])
REFERENCES [dbo].[city] ([cityID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Address] CHECK CONSTRAINT [FK_Address_city]
GO

/****** Object: ForeignKey [FK_Book_Category] Script Date: 05/19/2014


20:04:52 ******/
ALTER TABLE [dbo].[Book] WITH CHECK ADD CONSTRAINT
[FK_Book_Category] FOREIGN KEY([CategoryId])

REFERENCES [dbo].[Category] ([CategoryId])


ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Book] CHECK CONSTRAINT [FK_Book_Category]
GO

/****** Object: ForeignKey [FK_Book_Status] Script Date: 05/19/2014


20:04:52 ******/
ALTER TABLE [dbo].[Book] WITH CHECK ADD CONSTRAINT
[FK_Book_Status] FOREIGN KEY([StatusId])
REFERENCES [dbo].[Status] ([statuID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Book] CHECK CONSTRAINT [FK_Book_Status]
GO

/****** Object: ForeignKey [FK_book_Author_Author] Script Date:


05/19/2014 20:04:52 ******/
ALTER TABLE [dbo].[book_Author] WITH CHECK ADD CONSTRAINT
[FK_book_Author_Author] FOREIGN KEY([authorId])
REFERENCES [dbo].[Author] ([AuthorId])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[book_Author] CHECK CONSTRAINT
[FK_book_Author_Author]
GO

/****** Object: ForeignKey [FK_book_Author_Book] Script Date:


05/19/2014 20:04:52 ******/
ALTER TABLE [dbo].[book_Author] WITH CHECK ADD CONSTRAINT
[FK_book_Author_Book] FOREIGN KEY([bookId])
REFERENCES [dbo].[Book] ([BookId])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[book_Author] CHECK CONSTRAINT


[FK_book_Author_Book]
GO

/****** Object: ForeignKey [FK_brrow_Book] Script Date: 05/19/2014


20:04:52 ******/
ALTER TABLE [dbo].[TBorrow] WITH NOCHECK ADD CONSTRAINT
[FK_brrow_Book] FOREIGN KEY([BookId])
REFERENCES [dbo].[Book] ([BookId])
GO
ALTER TABLE [dbo].[TBorrow] CHECK CONSTRAINT [FK_brrow_Book]
GO

/****** Object: ForeignKey [FK_brrow_Users] Script Date: 05/19/2014


20:04:52 ******/
ALTER TABLE [dbo].[TBorrow] WITH CHECK ADD CONSTRAINT
[FK_brrow_Users] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([UserId])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[TBorrow] CHECK CONSTRAINT [FK_brrow_Users]
GO

/****** Object: ForeignKey [FK_Users_Address] Script Date: 05/19/2014


20:04:52 ******/
ALTER TABLE [dbo].[Users] WITH CHECK ADD CONSTRAINT
[FK_Users_Address] FOREIGN KEY([AddressId])
REFERENCES [dbo].[Address] ([AddressId])
GO
ALTER TABLE [dbo].[Users] CHECK CONSTRAINT [FK_Users_Address]
GO

THATS THE END OF THE DOCUMENT. GO AND GET SOME


BEVERAGE :)

You might also like