Lab 3 - Aliases TO Truncate
Lab 3 - Aliases TO Truncate
DESC employee;
Add other data :
INSERT INTO employee(ID, NAME, AGE, `Location`, SALARY) VALUES(12, 'Ahmed Saeed',
28,'Alex',3300);
INSERT INTO employee(ID, NAME, AGE, `Location`, SALARY) VALUES(13, 'Ashraf Samy',
31,'Matrouh',3800);
INSERT INTO employee(ID, NAME, AGE, `Location`, SALARY) VALUES(14, 'Said Wael',
36,'Aswan',4800);
INSERT INTO employee(ID, NAME, AGE, `Location`, SALARY) VALUES(15, 'Alaa Ali',
42,'Cairo',5500);
INSERT INTO employee(ID, NAME, AGE, `Location`, SALARY) VALUES(16, 'Ali Samy',
43,'Cairo',5800);
Display IDs, NAMEs, & SALARYs of employees whose SALARY is greater than or equal
to 10000
SELECT ID, NAME, SALARY FROM employee WHERE SALARY>=10000;
Display IDs, NAMEs, Ages, & SALARYs of employees whose SALARY is greater than or
equal to 10000 and age is less than 45
SELECT ID, NAME, SALARY, AGE FROM employee WHERE SALARY>=10000 AND AGE < 45;
Display all data of employees where the name starts with the litter ‘a’
SELECT * FROM employee
WHERE NAME LIKE 'a%';
Make an alteration in the salary column so that it doesn’t have a null value
ALTER TABLE employee
MODIFY SALARY DECIMAL (18, 2) NOT NULL;
DESC employee;
Make an alteration in the salary column so that it does have by default the value 5000
ALTER TABLE employee
MODIFY SALARY DECIMAL (18, 2) DEFAULT 5000.00;
INSERT INTO employee (ID, NAME, LOCATION, AGE) VALUES (019, 'Eve','USA', 35)
(error message Duplicate entry '35' for key 'AGE')
Create table orders: (ID, DATE, AMOUNT) and foreign key (CUSTOMER_ID) related to
employee’s ID
CREATE TABLE ORDERS (
ID INT NOT NULL,
DATE DATETIME,
CUSTOMER_ID INT references employee (ID),
AMOUNT double,
PRIMARY KEY (ID));
DESC orders;
Add column department id in ‘employee’ table and fill it with IDs : (1, 3, 5, 7, 9, 11, 13, 15,
17, 19)
UPDATE employee
SET Dep_ID = 1
WHERE ID = 1;
UPDATE employee
SET Dep_ID = 3
WHERE ID = 2;
UPDATE employee
SET Dep_ID = 5
WHERE ID = 3;
UPDATE employee
SET Dep_ID = 7
WHERE ID = 4;
UPDATE employee
SET Dep_ID = 9
WHERE ID = 5;
UPDATE employee
SET Dep_ID = 11
WHERE ID = 6;
UPDATE employee
SET Dep_ID = 13
WHERE ID = 7;
UPDATE employee
SET Dep_ID = 15
WHERE ID = 8;
UPDATE employee
SET Dep_ID = 17
WHERE ID = 9;
UPDATE employee
SET Dep_ID = 19
WHERE ID = 10;
SQL commands:
Report a table contains data about name, salary of employees and their department’s
names and IDs :
SELECT emp.ID, emp.NAME, emp.SALARY, emp.Dep_ID, dep.Name
FROM employee AS emp, department as dep
WHERE emp.Dep_ID = dep.D_ID
Report a table contains data about id, and name, for those whose salary is greater than or
equal to 8000 using alias to name columns of each data:
Display all data of employees who are not enrolled into a certain department :
Display all data of employees who are enrolled into a certain department :
Alphabetically grouped, display all data of employees who are enrolled into a certain department :
Delete the entire data from the department table but keep the table intact (safe from deletion)
OR
EMPTY the department table
TRUNCATE TABLE department