0% found this document useful (0 votes)
53 views5 pages

Assignment 1

1. A database called assignment1 is created and tables Department and Employee are created within it to store department and employee data. 2. Data is inserted into the Department table for 5 departments and into the Employee table for 6 employees which includes employee name, department number, and salary. 3. An attempt to insert a new employee with an invalid department number results in a foreign key constraint error since the department number does not exist in the Department table.

Uploaded by

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

Assignment 1

1. A database called assignment1 is created and tables Department and Employee are created within it to store department and employee data. 2. Data is inserted into the Department table for 5 departments and into the Employee table for 6 employees which includes employee name, department number, and salary. 3. An attempt to insert a new employee with an invalid department number results in a foreign key constraint error since the department number does not exist in the Department table.

Uploaded by

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

1.

Creating and using a Database in mysql



CREATE DATABASE assignment1;
SHOW DATABASES;
USE assignment1;

2. Creating tables in database assignment1



CREATE TABLE Department(DNO INT(2) PRIMARY KEY,
DNAME VARCHAR(10) NOTNULL);

CREATE TABLE Employee(ENO INT(2) PRIMARY KEY,


ENAME VARCHAR(10) NOT NULL, DNO INT(2), FOREIGN
KEY REFERENCES Department(DNO), SALARY INT(6));
3. Insert Datas in tables

INSERT INTO Department(DNO,DNAME) VALUES
(10,"Admin");
INSERT INTO Department(DNO,DNAME) VALUES
(20,"Accounts");
INSERT INTO Department(DNO,DNAME) VALUES
(30,"Sales");
INSERT INTO Department(DNO,DNAME) VALUES
(40,"Marketing");
INSERT INTO Department(DNO,DNAME) VALUES
(50,"Purchasing");
INSERT INTO Employee(ENO,ENAME,DNO,SALARY)
VALUES (1,"Amal",10,30000);
INSERT INTO Employee(ENO,ENAME,DNO,SALARY)
VALUES (2,"Shyamal",30,50000);
INSERT INTO Employee(ENO,ENAME,DNO,SALARY)
VALUES (3,"kamal",40,10000);
INSERT INTO Employee(ENO,ENAME,DNO,SALARY)
VALUES (4,"nirmal",50,60000);
INSERT INTO Employee(ENO,ENAME,DNO,SALARY)
VALUES (5,"Bimal",20,40000);
INSERT INTO Employee(ENO,ENAME,DNO,SALARY)
VALUES (6,"Parimal",20,20000);
4. Display all data from the Department table.

SELECT * FROM Department;
5. Display all data from the Employee table.

SELECT * FROM Employee;

6. Insert [1,akash,60,70000] value in Employee table(copy error


message).

UPDATE Employee SET ENO=1,
ENAME="akash",DNO=60,SALARY=70000;

ERROR 1452 (23000): Cannot add or update a child row: a


foreign key constraint fails (`assignment1`.`employee`,
CONSTRAINT `employee_ibfk_1` FOREIGN KEY (`DNO`)
REFERENCES `department` (`DNO`))

7. Insert [7,akash,60,70000] value in Employee table(copy error


message).

UPDATE Employee SET
ENO=7,ENAME="akash",DNO=60,SALARY=70000;
ERROR 1452 (23000): Cannot add or update a child row: a foreign
key constraint fails (`assignment1`.`employee`, CONSTRAINT
`employee_ibfk_1` FOREIGN KEY (`DNO`) REFERENCES
`department` (`DNO`))

8. Display name and salary of all employees whose department no is


10.

SELECT ENAME,SALARY FROM Employee WHERE


DNO=10;

9. Display the name and salary of all employees who are working in the
Accounts department.

SELECT ENAME,SALARY FROM EMPLOYEE,DEPARTMENT


WHERE EMPLOYEE.DNO=DEPARTMENT.DNO AND
DNAME='Accounts';

You might also like