Assignment

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

ASSIGNMENT

ROLL NO: 05
NAME Syed Aqib Shah
CLASS BBA (7thSemester)
SECTION BBA (HR)

INSTITUTE OF MANAGEMENT STUDIES


UNIVERSITY OF PESHAWAR
(Session 2017-2021)
PART#01:

CREATE TABLE "company" (


"ID" INTEGER,
"Name" TEXT,
"Gender" TEXT,
"Nationality" TEXT,
"CellNo" INTEGER

CREATE TABLE AKSCHOOL ("TEACHER ID" INT, "STUDANT NAME" TEXT,


"STUDENT GENDER" INT, "CLASS" INT)
Id Name Gender class

Inserting data:
INSERT INTO AKSCHOOL ("TEACHERS ID" , "NAME", "GENDER", "CLASS")
VALUES ("01", "AMAR", "MALE", "8th")
INSERT INTO AKSCHOOL ("TEACHER ID" , "NAME", "GENDER", "CLASS")
VALUES ("02", "AMIR", "MALE", "7th")
INSERT INTO AKSCHOOL ("TEACHERID" , "NAME", "GENDER", "CLASS")
VALUES ("03", "AMEEN", "MALE", "6th")
INSERT INTO AKSCHOOL ("TEACHER ID" , "NAME", "GENDER", "CLASS")
VALUES ("04", "AMIT", "MALE", "5th")

Id Name Gender CLASS

1 AMAR Male 8
2 AMIR Male 7
3 AMEEN Male 6
4 AMIT Male 5
Entry of TEACHERS:

INSERT INTO ASSETS ("TEACHER ID" , "NAME", "GENDER", "CLASS")


VALUES ("06", "FARHAN", "MALE", "8th")
INSERT INTO ASSETS ("TEACHER ID" , "NAME", "GENDER", "CLASS")
VALUES ("07", "FAISAL", "MALE", "7th")
INSERT INTO ASSETS ("TEACHER ID" , "NAME", "GENDER", "CLASS")
VALUES ("08", "FAHEEM", "MALE", "6th")
INSERT INTO ASSETS ("TEACHER ID" , "NAME", "GENDER", "CLASS")
VALUES ("09", "FURQAN", "MALE", "5th")

Id Name Gender CLASS

1 FARHAN Male 6
2 FAISAL Male 7
3 FAHEEM Male 8
4 FURQAN Male 9

Question 2,
Part 2: clearly mention primary and foreign key…tables
Adding Primary Key to a new table of employees name:

CREATE TABLE TEACHERS (ID int NOT NULL, LastName varchar(50) NOT
NULL FirstName varchar(40) Age int, PRIMARY KEY (ID)
);
ID Last Name First Name Service

1 Ayub Khan 5 years

2 Altaf shah 6 years

3 usman Khwaja 9 years

Primary Key

Foreign Key for the table - company:

ALTER TABLE company


ADD FOREIGN KEY (name) REFERENCES employees(ID);

Id Name Gender Nationality CellNo

1 Ayub Male Pakistani +92430258890


2 Jordan Male American +11430258891
3 jack Male British +44430258892
4 samrath Male Indian +91430258893

Foreign Key

Question 2, Part 3:
Use all Query:
1. Select Distinct
SELECT DISTINCT Name FROM company
Result:

1 Ismael

2 Jordan
3 alex

4 Samrath

2. Where Clause:
Query
SELECT Name FROM company WHERE id=1
1 Ismael

3. Like Operator:
Query
SELECT Name FROM company WHERE name like "j%"
Result:

1 Jordan

2 John

4. Order By:

a. Ascending
Query
SELECT Name FROM company ORDER by name ASC
Result

1 John

2 Jordan

3 Muhammad

4 Virat
b. Descending

Query

SELECT Name FROM company ORDER by name DESC

Result

1 Samrath

2 Ismael

3 John

4 Jordan

5. Having Clause:
Query
SELECT id FROM company group by id having 1
Result:

1 1

6. Group By:
Query:
SELECT id FROM company group by Name
Result:

1 3

2 2

3 1

4 4

Question 2, Part 4:
Explain how Join Query will be useful in example:
Join query or join clause is used to combine the rows from two or more tables that are
based on the related column between them.
How it is useful:
Join query is very useful in this example which is discussed above that it performs
many functions especially recover the specific data from tables. It eliminates the
confusion to find it in spread and huge amount of data; it allows viewing or finding it
in a single data-sheet rather than searching from the start to the end.

 Left join returns all records from left table and match record with right table
 Right join return all records from the right table and match records from left
table
 Full join returns all records when there is a match in either left or right table.
 Inner join returns records that have matching values in both tables.

Inner query of employee and customer which joins:


Select employee.Column(Id),Customer.name

You might also like