Sahil 7-9

You might also like

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

EXPERIMENT NO: - 07

Aim: Generating sub query.

SQL provides a mechanism for the nesting of subqueries.

A subquery is a select-from-where expression that is nested within anther query.

A common use of subqueries is to perform tests for set membership, set comparisons, and set cardinality.

Example 1: - Find all the customer_id and customer_name who belongs to same city by fetching data from 2
different tables.

Syntax: select customer_id, customer_name from borrower where customer_id in (select customer_id from
customer where city = ‘Hamirpur’);

Example 2: - Find all customers who belongs to same city by fetching data from same table.

Page | 37
Syntax: select customer_id, customer_name, street from customer where customer_id in (select customer_id
from customer where city=’Hamirpur’);

Page | 38
EXPERIMENT NO: - 08

Aim: Deleting Records (Delete single, Multiple and all records).

Deletion: The delete statement is used to delete existing records in a table.

There are three ways in which we can delete records in a table.

Deleting a single record

Deleting multiple records

Deleting all records

Delete single: we can delete a single record in a table using where clause with delete command.

Syntax: DELETE FROM <table_name> WHERE <column_name> = <value>;

Example: delete from customer where customer_name = ‘Atharva’;

Page | 39
Delete Multiple: We can delete multiple records by using in, and, or operators with delete command.

Syntax: DELETE FROM <table_name> WHERE <column_name> IN (value 1, value 2, value 3, etc...);

Example: delete from customer where customer_name in (‘Disha’, ’Raghav Soni’, ’Shruti’);

Delete All: To delete all the records in a table use truncate command.

Syntax: truncate table <table_name>;

Example: truncate table borrower;

Page | 40
EXPERIMENT NO: - 09

Aim: Dropping tables:

Dropping table that has primary key

Dropping table that has foreign key

Dropping table that has primary key: To drop table a table that has primary key in it, just simply use MySQL
drop command. Make sure that the table to be deleted is not referenced by any other table.

Syntax: drop table <table_name>;

Example: drop table depositer;

Dropping table that has foreign key:To drop a table that has foreign key in it, just simply use MySQL drop
command. Make sure that the table to be deleted is not referenced by any other table.
Page | 41
Syntax: drop table <table_name>;

Example: drop table borrower;

Page | 42

You might also like