Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views2 pages

SQL Database Setup Guide

The document outlines the creation of an employee database named 'employee' along with two tables: 'Empdata' for employee information and 'Department' for department details. It includes sample data insertion for both tables and establishes a foreign key relationship between 'Empdata' and 'Department'. Additionally, it updates the 'Empdata' table with department IDs for specific employees.

Uploaded by

eldinsafe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

SQL Database Setup Guide

The document outlines the creation of an employee database named 'employee' along with two tables: 'Empdata' for employee information and 'Department' for department details. It includes sample data insertion for both tables and establishes a foreign key relationship between 'Empdata' and 'Department'. Additionally, it updates the 'Empdata' table with department IDs for specific employees.

Uploaded by

eldinsafe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

-- 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

You might also like