Professional Documents
Culture Documents
Assignment
Assignment
Assignment
ROLL NO: 05
NAME Syed Aqib Shah
CLASS BBA (7thSemester)
SECTION BBA (HR)
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")
1 AMAR Male 8
2 AMIR Male 7
3 AMEEN Male 6
4 AMIT Male 5
Entry of TEACHERS:
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
Primary Key
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
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.