Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions task.sql
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
-- Create database and tables
CREATE DATABASE ShopDB
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CREATE DATABASE statement is missing a semicolon at the end. Each SQL statement should be properly terminated for the script to be valid.


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the requirements, the script should first delete the ShopDB database if it already exists. Please add DROP DATABASE IF EXISTS ShopDB; at the very beginning of this file, before the CREATE DATABASE statement.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script will fail because you're trying to use the ShopDB database before it has been created. You've dropped it on line 1, but you need to add a CREATE DATABASE ShopDB; command before this line.

CREATE DATABASE ShopDB;
USE ShopDB;

CREATE TABLE Countries (
ID INT,
Name VARCHAR(50),
PRIMARY KEY (ID)
);
Create Table Countries (
ID INT AUTO_INCREMENT,
PRIMARY KEY (ID),
NAME VARCHAR(50)
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CREATE TABLE statement should be terminated with a semicolon.


CREATE TABLE ProductInventory (
ID INT,
ProductName VARCHAR(50),
WarehouseAmount INT,
CREATE TABLE Warehouses (
ID INT AUTO_INCREMENT,
PRIMARY KEY (ID),
WarehouseName VARCHAR(50),
WarehouseAddress VARCHAR(50),
WarehouseAddress VARCHAR(50),
CountryID INT,
FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION,
PRIMARY KEY (ID)
);

-- Populate test data

INSERT INTO Countries (ID,Name)
VALUES (1, 'Country1');
INSERT INTO Countries (ID,Name)
VALUES (2, 'Country2');

INSERT INTO ProductInventory (ID,ProductName,WarehouseAmount,WarehouseName,WarehouseAddress,CountryID)
VALUES (1, 'AwersomeProduct', 2, 'Warehouse-1', 'City-1, Street-1',1);
INSERT INTO ProductInventory (ID,ProductName,WarehouseAmount,WarehouseName,WarehouseAddress,CountryID)
VALUES (2, 'AwersomeProduct', 5, 'Warehouse-2', 'City-2, Street-2',2);
FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CREATE TABLE statement is also missing a terminating semicolon.


CREATE TABLE ProductInventory (
ID INT AUTO_INCREMENT,
PRIMARY KEY (ID),
Name VARCHAR(50),
Amount INT,
WarehouseID INT,
FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID) ON DELETE NO ACTION
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CREATE TABLE statement is missing its terminating semicolon. Ensure all SQL statements end with a ; for the script to run correctly.


INSERT INTO Countries (NAME)
VALUES ('Country1'), ('Country2');


INSERT INTO Warehouses (WarehouseName, WarehouseAddress, CountryID)
VALUES ('Warehouse-1', 'City-1, Street-1', 1), ('Warehouse-2', 'City-2, Street-1', 2);

INSERT INTO ProductInventory (Name, Amount, WarehouseID)
VALUES ('Product-1', 2, 1), ('Product-2', 5, 2)
Loading