drop create tables insert data
-- Drop existing tables if they exist
DROP TABLE IF EXISTS staffs;
DROP TABLE IF EXISTS stores;
DROP TABLE IF EXISTS stocks;
GO
-- Create stores table
CREATE TABLE stores (
store_id INT PRIMARY KEY,
store_name VARCHAR(100) NOT NULL,
store_address VARCHAR(200)
);
-- Create staffs table
CREATE TABLE staffs (
staff_id INT PRIMARY KEY,
store_id INT NOT NULL,
first_name VARCHAR(50),
last_name VARCHAR(50),
email VARCHAR(100) UNIQUE,
FOREIGN KEY (store_id) REFERENCES stores(store_id)
);
-- Create stocks table
CREATE TABLE stocks (
stock_id INT PRIMARY KEY,
store_id INT NOT NULL,
product_id INT NOT NULL,
quantity INT NOT NULL,
FOREIGN KEY (store_id) REFERENCES stores(store_id)
);
-- Insert sample data into stores
INSERT INTO stores (store_id, store_name, store_address) VALUES
(1, 'Central Store', 'Main Road'),
(2, 'North Store', 'North Avenue'),
(3, 'South Store', 'South Street');
-- Insert sample data into staffs
INSERT INTO staffs (staff_id, store_id, first_name, last_name, email) VALUES
(101, 1, 'Alice', 'Smith', 'alice@central.com'),
(102, 1, 'Bob', 'Johnson', 'bob@central.com'),
(103, 2, 'Charlie', 'Brown', 'charlie@north.com'),
(104, 3, 'Diana', 'White', 'diana@south.com'),
(105, 3, 'Ethan', 'Black', 'ethan@south.com');
-- Insert sample data into stocks
INSERT INTO stocks (stock_id, store_id, product_id, quantity) VALUES
(1001, 1, 501, 20),
(1002, 1, 502, 15),
(1003, 2, 501, 30),
(1004, 2, 503, 25),
(1005, 3, 504, 40),
(1006, 3, 505, 10),
(1007, 3, 501, 5);