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

SQL Assingnment

The document describes creating a database table called employees with various columns like ID, name, age etc. and inserting sample data. It then discusses changing the data type of the phone number column and performing other queries like selecting distinct job titles, updating a date of birth, deleting records, creating another table called employee_insurance and inserting data into it, and adding an email column to the employees table.

Uploaded by

Sifat Khan
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)
25 views

SQL Assingnment

The document describes creating a database table called employees with various columns like ID, name, age etc. and inserting sample data. It then discusses changing the data type of the phone number column and performing other queries like selecting distinct job titles, updating a date of birth, deleting records, creating another table called employee_insurance and inserting data into it, and adding an email column to the employees table.

Uploaded by

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

Q: Create a table called employees with the following columns and datatypes:

ID - INT autoincrement
last_name - VARCHAR of size 50 should not be null
first_name - VARCHAR of size 50 should not be null
age - INT
job_title - VARCHAR of size 100
date_of_birth - DATE
phone_number - INT
insurance_id - VARCHAR of size 15

SET ID AS PRIMARY KEY DURING TABLE CREATION

Ans:
CREATE TABLE
employees ( ID INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
age INT,
job_title VARCHAR(100),
date_of_birth DATE,
phone_number INT,
nsurance_id VARCHAR(15) );

Q: Add the following data to this table in a SINGLE query:

Smith | John | 32 | Manager | 1989-05-12 | 5551234567 | INS736 |

INSERT INTO employees (first_name,Last_name,age,job,DOB,Cell_number,insurance_id)


VALUES(‘Smith’,’Jhon’,32,’Manager’,’ 1989-05-12’, 5551234567,’ INS736’)

Johnson | Sarah | 28 | Analyst | 1993-09-20 | 5559876543 | INS832 |

INSERT INTO employees (first_name,Last_name,age,job,DOB,Cell_number,insurance_id)


VALUES(‘Johnson’,’Sarah’,28,’Analyst’,’ 1993-09-20’, 5559876543,’ INS832’)

Davis | David | 45 | HR | 1976-02-03 | 5550555995 | INS007 |

INSERT INTO employees (first_name,Last_name,age,job,DOB,Cell_number,insurance_id)


VALUES(‘Davis’,’David’,45,’HR’,’ 1976-02-03’, 550555995,’ INS007’)

Q: While inserting the above data, you might get error because of Phone number
column.
-- As phone_number is INT right now. Change the datatype of phone_number to make them
strings of FIXED LENGTH of 10 characters.
-- Do some research on which datatype you need to use for this.

Ans: We can use CHAR datatypes can be used of fixed 10 length.

ALTER TABLE employees


MODIFY cell_number CHAR(10);
Explore unique job titles

SELECT DISTINCT job from employees;

Name the top three youngest employees


SELECT first_name,age
from employees
ORDER BY age
limit 3;

Update date of birth for Alex Thompson as it is 1992-06-24

UPDATE employees
SET DOB = ‘1992-06-24’
WHERE first_name = ‘Alex’ AND last_name=’ Thompson’

Delete the data of employees with age greater than 30

DELETE from employees


WHERE age >30;

Create a table called employee_insurance with the following columns and datatypes:

insurance_id VARCHAR of size 15


insurance_info VARCHAR of size 100

Make insurance_id the primary key of this tabl

CREATE TABLE employee_insurance


(insurance_id VARCHAR(15) PRIMARY KEY,
insurance_info VARCHAR(100)
);

Insert the following values into employee_insurance:

"INS736", "unavailable"

INSERT INTO employee_insurance (insurance_id, insurance_info)


VALUES(‘INS736’,’unavailable’)

Add a column called email to the employees table. Remember to set an appropriate
datatype

ALTER TABLE employees


ADD clounm email VARCHAR();

Add the value "unavailable" for all records in email in a SINGLE query

UPDATE employees
SET email = ‘unavailable’ ;

You might also like