USE [master]
GO
/****** Object:  Database [librarydb]    Script Date: 12.12.2023 00:16:12 ******/
CREATE DATABASE [librarydb]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'librarydb', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\DATA\librarydb.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )
 LOG ON 
( NAME = N'librarydb_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\DATA\librarydb_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
 WITH CATALOG_COLLATION = DATABASE_DEFAULT, LEDGER = OFF
GO
ALTER DATABASE [librarydb] SET COMPATIBILITY_LEVEL = 160
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [librarydb].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [librarydb] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [librarydb] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [librarydb] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [librarydb] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [librarydb] SET ARITHABORT OFF 
GO
ALTER DATABASE [librarydb] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [librarydb] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [librarydb] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [librarydb] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [librarydb] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [librarydb] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [librarydb] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [librarydb] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [librarydb] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [librarydb] SET  DISABLE_BROKER 
GO
ALTER DATABASE [librarydb] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [librarydb] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [librarydb] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [librarydb] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [librarydb] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [librarydb] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [librarydb] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [librarydb] SET RECOVERY FULL 
GO
ALTER DATABASE [librarydb] SET  MULTI_USER 
GO
ALTER DATABASE [librarydb] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [librarydb] SET DB_CHAINING OFF 
GO
ALTER DATABASE [librarydb] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO
ALTER DATABASE [librarydb] SET TARGET_RECOVERY_TIME = 60 SECONDS 
GO
ALTER DATABASE [librarydb] SET DELAYED_DURABILITY = DISABLED 
GO
ALTER DATABASE [librarydb] SET ACCELERATED_DATABASE_RECOVERY = OFF  
GO
EXEC sys.sp_db_vardecimal_storage_format N'librarydb', N'ON'
GO
ALTER DATABASE [librarydb] SET QUERY_STORE = ON
GO
ALTER DATABASE [librarydb] SET QUERY_STORE (OPERATION_MODE = READ_WRITE, CLEANUP_POLICY = (STALE_QUERY_THRESHOLD_DAYS = 30), DATA_FLUSH_INTERVAL_SECONDS = 900, INTERVAL_LENGTH_MINUTES = 60, MAX_STORAGE_SIZE_MB = 1000, QUERY_CAPTURE_MODE = AUTO, SIZE_BASED_CLEANUP_MODE = AUTO, MAX_PLANS_PER_QUERY = 200, WAIT_STATS_CAPTURE_MODE = ON)
GO
USE [librarydb]
GO
/****** Object:  Table [dbo].[access]    Script Date: 12.12.2023 00:16:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[access](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[permissions] [bit] NOT NULL,
 CONSTRAINT [PK_access] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[book]    Script Date: 12.12.2023 00:16:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[book](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[title] [nvarchar](max) NOT NULL,
	[author] [nvarchar](max) NOT NULL,
	[year] [int] NOT NULL,
	[description] [nvarchar](max) NOT NULL,
	[image] [nvarchar](max) NOT NULL,
 CONSTRAINT [PK_book] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[review]    Script Date: 12.12.2023 00:16:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[review](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[id_user] [int] NOT NULL,
	[rating] [int] NOT NULL,
	[description] [nvarchar](max) NOT NULL,
 CONSTRAINT [PK_review] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[user]    Script Date: 12.12.2023 00:16:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[user](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[email] [nvarchar](max) NOT NULL,
	[username] [nvarchar](16) NOT NULL,
	[password] [nvarchar](30) NOT NULL,
	[id_access] [int] NOT NULL,
 CONSTRAINT [PK_user] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[review]  WITH CHECK ADD  CONSTRAINT [FK_review_user] FOREIGN KEY([id_user])
REFERENCES [dbo].[user] ([id])
GO
ALTER TABLE [dbo].[review] CHECK CONSTRAINT [FK_review_user]
GO
ALTER TABLE [dbo].[user]  WITH CHECK ADD  CONSTRAINT [FK_user_access] FOREIGN KEY([id_access])
REFERENCES [dbo].[access] ([id])
GO
ALTER TABLE [dbo].[user] CHECK CONSTRAINT [FK_user_access]
GO
USE [master]
GO
ALTER DATABASE [librarydb] SET  READ_WRITE 
GO
