0% found this document useful (0 votes)
0 views

DATA TYPES IN SQL updated

The document outlines a class activity focused on SQL data types, including creating a database and table for employees with specific fields and constraints. It provides SQL queries for inserting records, altering the table structure, updating records, and deleting entries. Additionally, it includes examples of various data types such as integer, floating point, character, date, and boolean types in SQL.

Uploaded by

zalanshahzada
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

DATA TYPES IN SQL updated

The document outlines a class activity focused on SQL data types, including creating a database and table for employees with specific fields and constraints. It provides SQL queries for inserting records, altering the table structure, updating records, and deleting entries. Additionally, it includes examples of various data types such as integer, floating point, character, date, and boolean types in SQL.

Uploaded by

zalanshahzada
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

DATA TYPES IN SQL:

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:

CREATE TABLE Employees (

EmployeeID INT PRIMARY KEY,

Age TINYINT CHECK (Age BETWEEN 18 AND 60)

);

2. Floating Point & Decimal Types:

For Example:

CREATE TABLE Products (

ProductID INT PRIMARY KEY,

Price DECIMAL(6,2) CHECK (Price > 0)

);

3. Character/String Types:
CREATE TABLE Users (

UserID INT PRIMARY KEY,

Username VARCHAR(50) NOT NULL,

Password CHAR(10) NOT NULL

);

4. Date and Time Types:

CREATE TABLE Orders (

OrderID INT PRIMARY KEY,

OrderDate DATE NOT NULL,

DeliveryTime TIME NOT NULL

);

5. Boolean Type:
CREATE TABLE Employees (

EmployeeID INT PRIMARY KEY,

IsActive BOOLEAN DEFAULT TRUE

);

You might also like