-- Create the employee database
CREATE DATABASE employee;
GO
-- Use the employee database
USE employee;
GO
-- Create the Empdata table
CREATE TABLE Empdata (
empId INT PRIMARY KEY,
empname VARCHAR(50),
empaddress VARCHAR(100),
empphonenumber VARCHAR(20),
salary DECIMAL(10, 2)
);
-- Insert sample data into Empdata table
INSERT INTO Empdata (empId, empname, empaddress, empphonenumber,
salary)
VALUES
(1, 'John Doe', '123 Main St', '555-1234', 50000.00),
(2, 'Jane Smith', '456 Oak Ave', '555-5678', 60000.00),
(3, 'David Lee', '789 Elm St', '555-9012', 45000.00),
(4, 'Sarah Jones', '101 Pine Rd', '555-3456', 55000.00),
(5, 'Michael Brown', '202 Maple Ln', '555-7890', 65000.00),
(6, 'Emily Davis', '303 Cedar Dr', '555-1234', 52000.00);
-- Create the Department table
CREATE TABLE Department (
deptid INT PRIMARY KEY,
deptname VARCHAR(50)
);
-- Insert data into Department table
INSERT INTO Department (deptid, deptname)
VALUES
(1, 'HR'),
(2, 'Finance'),
(3, 'IT');
-- Add a foreign key constraint to Empdata table to connect with Department
table
ALTER TABLE Empdata
ADD deptId INT,
CONSTRAINT FK_Empdata_Department FOREIGN KEY (deptId) REFERENCES
Department(deptid);
-- Update Empdata table with department IDs (assuming some sample
assignments)
UPDATE Empdata
SET deptId = 1 WHERE empId IN (1, 2);
UPDATE Empdata
SET deptId = 2 WHERE empId IN (3, 4