Data Definition and Data Types - 13. Problem - Movies Database
Здравейте,
Judge ми дава Compile time error - Database 'Movies' does not exist. Make sure that the name is entered correctly.
С този код :
CREATE DATABASE [Movies]
USE [Movies];
CREATE TABLE [Directors]
(
Id INT PRIMARY KEY IDENTITY,
DirectorName NVARCHAR(50) NOT NULL,
Notes NVARCHAR (MAX),
)
CREATE TABLE [Genres]
(
Id INT PRIMARY KEY IDENTITY,
GenreName NVARCHAR(50) NOT NULL,
Notes NVARCHAR (MAX),
)
CREATE TABLE [Categories]
(
Id INT PRIMARY KEY IDENTITY,
CategoryName NVARCHAR(50) NOT NULL,
Notes NVARCHAR (MAX),
)
CREATE TABLE [Movies]
(
Id INT PRIMARY KEY IDENTITY,
Title NVARCHAR (150) NOT NULL,
DirectorId INT NOT NULL,
CopyrightYear SMALLINT NOT NULL,
CONSTRAINT CHK_Year_Range CHECK (LEN([CopyrightYear])>=1800 AND LEN([CopyrightYear])<=2023),
[Length] DECIMAL(4,2) NOT NULL,
GenreId INT NOT NULL,
CategoryId INT NOT NULL,
Rating DECIMAL(3,2),
Notes NVARCHAR (MAX),
)
ALTER TABLE [Movies]
ADD CONSTRAINT FK_DirectorId FOREIGN KEY (DirectorId) REFERENCES [Directors](Id);
ALTER TABLE [Movies]
ADD CONSTRAINT FK_GenreId FOREIGN KEY (GenreId) REFERENCES [Genres](Id);
ALTER TABLE [Movies]
ADD CONSTRAINT FK_CategoryId FOREIGN KEY (CategoryId) REFERENCES [Categories](Id);
ALTER TABLE [Movies]
DROP CONSTRAINT CHK_Year_Range;
ALTER TABLE [Movies]
ADD CONSTRAINT CHK_Year_Range CHECK (CopyrightYear >= 1800 AND CopyrightYear <= 2023)
INSERT INTO [Directors] (DirectorName, Notes)
VALUES
('Steven Spielberg', 'Renowned director known for blockbuster films.'),
('Christopher Nolan', 'Acclaimed filmmaker with a focus on mind-bending narratives.'),
('Quentin Tarantino', 'Director famous for his unique storytelling style.'),
('Greta Gerwig', 'Talented director known for her indie films.'),
('Martin Scorsese', 'Legendary director with a career spanning decades.');
INSERT INTO [Genres] (GenreName, Notes)
VALUES
('Action', 'Genre characterized by high-energy, thrilling sequences.'),
('Drama', 'Genre focusing on character development and emotional storytelling.'),
('Comedy', 'Genre known for humor and lighthearted storytelling.'),
('Science Fiction', 'Genre that explores speculative and futuristic concepts.'),
('Horror', 'Genre designed to evoke fear and suspense.');
INSERT INTO [Categories] (CategoryName, Notes)
VALUES
('Adventure', 'Category for adventurous and epic films.'),
('Romance', 'Category for films centered on romantic relationships.'),
('Crime', 'Category for crime and investigative films.'),
('Fantasy', 'Category for films set in fantastical worlds.'),
('Biography', 'Category for biographical films about real-life individuals.');
INSERT INTO [Movies] (Title, DirectorId, CopyrightYear, [Length], GenreId, CategoryId, Rating, Notes)
VALUES
('Jurassic Park', 1, 1993, 2.07, 1, 1, 4.5, 'Dinosaurs come to life in this adventure.'),
('Inception', 2, 2010, 2.28, 4, 3, 4.8, 'A mind-bending journey into dreams.'),
('Pulp Fiction', 3, 1994, 2.33, 1, 3, 4.7, 'Quirky characters in intertwining stories.'),
('Lady Bird', 4, 2017, 1.34, 2, 2, 4.3, 'Coming-of-age drama set in Sacramento.'),
('Goodfellas', 5, 1990, 2.25, 3, 3, 4.6, 'A classic mobster film directed by Scorsese.');
Не мога да разбера на какво се дължи това