DATA TYPES IN SQL updated
DATA TYPES IN SQL updated
CLASS ACTIVITY:
1. Create Database EMPLOYEE,
QUERY-> CREATE DATABASE EMPLOYEE
2. Then add the following fields, Emp ID (ID should be primary Key,
employee name, age (Age must be 20+), date of birth, salary, department)
QUERY-> CREATE TABLE employee(Emp_ID INT Primary Key, Emp_name
Varchar(30) not null, Age INT check (Age>=20), DOB date, salary INT,
Department Varchar(30)
3. Add 5 different records.
QUERY-> Insert into employee (Emp_ID, Emp_name, Age, DOB, salary,
Department) Values (1,”Hammad”, 24, “1111-11-11”, 20000, “BS-SE),
(2,”Hammad”, 24, “1111-11-11”, 20000, “BS-SE), (3,”Hammad”, 24, “1111-
11-11”, 20000, “BS-SE), (4,”Hammad”, 24, “1111-11-11”, 20000, “BS-SE),
(5,”Hammad”, 24, “1111-11-11”, 20000, “BS-SE)
4. Add 2 extra columns email and Gender.
QUERY-> Alter table employee Add email Varchar(30), Add Gender
Varchar(6)
5. Delete salary Column.
ALTER TABLE employee DROP COLUMN Salary;
6. Update Rows, Update Gender and Email in every column.
Update employee SET email = CASE
Where emp_ID =1 THEN “[email protected]”
Repeat the same for all ids…
END,
Gender = CASE
Where Emp_ID = 1 Then “Male”
Repeat the same for all ids…
END
Where Emp_ID IN (1,2,3,4,5);
7. Delete the Record whose id is 002.
QUERY-> DELETE FROM employee WHERE Emp_ID=002;
1. Integer Types:
For Example:
);
For Example:
);
3. Character/String Types:
CREATE TABLE Users (
);
);
5. Boolean Type:
CREATE TABLE Employees (
);