You are on page 1of 59

Hemang Goel 02361188820

Assignment 1
Date: 14-09-2022

CREATE TABLE SQL command


To column parameters specify the names of the table and the datatype parameter specifies the
type of the data the column can hold (eg. Varchar, integer/number, date, char, etc.)

Syntax
Create table < Table_Name >(
<Column Name 1> <Data type>(size),

<Column Name 2> <Data type>(size),


<Column Name 1> <Data type>(size),

.
.

<Column Name n> <Data type>(size),


);
Question 1: Create the table name student with the column names student enrol, Name, Class
and sec, Mobile number, City with appropriate data type.

1
Hemang Goel 02361188820

INSERT INTO command


This command helps to insert the value in the columns of the table

Syntax
Insert into table_name(column1, column2, ………)
Values (value1, value2, ............ );

Question 2: Insert 5 row in the table student.

2
Hemang Goel 02361188820

3
Hemang Goel 02361188820

DESCRIPTION command
It is used to know the description of the data table.

Syntax
Desc <Table_Name>;

Question 3: Description of your selected object.

4
Hemang Goel 02361188820

Assignment 2
Date: 27-09-2022

Question 1: Create a table name client_master with the following columns: -


a. Client_no
b. Name
c. Address
d. City
e. Pincode
f. State
g. Bal_due

5
Hemang Goel 02361188820

Question 2: Insert any 5 rows in the above columns.

6
Hemang Goel 02361188820

7
Hemang Goel 02361188820

8
Hemang Goel 02361188820

9
Hemang Goel 02361188820

Question 3: Select the whole table.

10
Hemang Goel 02361188820

Question 4: Display all the details where the city is ‘Delhi’.

Or you can use syntax- select * from client_master where city=’delhi’;

Question 5: Display the names of the clients who belongs to ‘Haryana’.

11
Hemang Goel 02361188820

Question 6: Display the Client_No and name whose baldue is greater than ‘5000’.

Question 7: Display the client_no , city and pin code who belongs to Delhi.

12
Hemang Goel 02361188820

Question 8: Display the name and baldue of those clients who belongs to Rajasthan.

13
Hemang Goel 02361188820

Assignment 3
Date:27-09-2022

Question 1: Create a table name client_master with the following columns: -

a. Client_no
b. Name
c. Address
d. City
e. Pincode
f. State
g. Bal_due

14
Hemang Goel 02361188820

Question 2: Insert any 5 rows in the above columns.

15
Hemang Goel 02361188820

16
Hemang Goel 02361188820

Question 3: Display all the records from client_master table who belongs to Delhi and the
baldue is less than 5000.

17
Hemang Goel 02361188820

Question 4: Display all the records from client_master table where city= Delhi or Gurugram.

Question 5 : Display all those records from client_master table whose state is Uttar Pradesh
and city must be Noida or Ghaziabad.

18
Hemang Goel 02361188820

Question 6: Display all the records from client_master table who don’t belong to Delhi.

OR

19
Hemang Goel 02361188820

Assignment 4
Date: 27-09-2022

DELETE SQL Command


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

Syntax
Delete from <Table Name>
Where < Condition>;

Question 1: Delete the record for those Client whose belong to Delhi.

DISTINCT command
The SELECT DISTINCT statement is used to return only distinct (different) values.

Syntax
Select distinct <column_name> From table_name;

20
Hemang Goel 02361188820

Question 2: To Display the distinct city of client from Client_Master_5B table.

SELECT command
The SELECT statement is used to select data from a database. The data returned is stored in a
result table, called the result-set.

Syntax

Select column1, column2, ...


from table_name;

For entire table


Select * from table_name;

21
Hemang Goel 02361188820

Question 3: Find the names of all clients.

Question 4: Retrieve the entire contents of Client_Master_5B of table.

22
Hemang Goel 02361188820

Question 5: Display name and city of all the client.

Question 6: Delete the record from Client_Master_5B table where Column State holds the
value Tamil Nadu.

23
Hemang Goel 02361188820

Question 7: Insert a new record.

24
Hemang Goel 02361188820

Question 8: Delete the record from Client_Master_5B where balance due is less than 10000.

25
Hemang Goel 02361188820

Assignment 5
Date: 27-09-2022

Primary Key
The PRIMARY KEY constraint uniquely identifies each record in a table. Primary keys must
contain UNIQUE values and cannot contain NULL values. A table can have only ONE
primary key; and in the table, this primary key can consist of single or multiple columns
(fields).

Foreign Key
The FOREIGN KEY constraint is used to prevent actions that would destroy links between
tables.

A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY
KEY in another table.

The table with the foreign key is called the child table, and the table with the primary key is
called the referenced or parent table.

Syntax
create table ABC (

Enrollment number(10) primary key,


Name char(15) not null,

………);

26
Hemang Goel 02361188820

Question 1: Create the table name student_5B or student_5bb with the column names
Enrollment_No with primary key, Name, Email_ID, Address, Mobile, DOB, Marks with
appropriate data type.

Question 2: Insert five data in student_5bb table.

27
Hemang Goel 02361188820

28
Hemang Goel 02361188820

29
Hemang Goel 02361188820

SQL ORDER by clause


Its is used to short the result in ascending or descending order.

Syntax
Select column 1, column 2,……
From table_name,
Where condition

Order by clause name asc/desc;

Question 3: To show the name of all clients in ascending order.

Question 4: To show all the records from Client_Master_5bb table in descending order of
City name.

30
Hemang Goel 02361188820

SQL AND, OR and NOT operators


⮚ Where clause can be combines AND, OR operators.
⮚ The AND, OR operators are used to filter records based on more than one condition.
⮚ The AND operators record if all the condition separated by AND are true.
⮚ The OR operators display if any of the condition separated by OR is true.
⮚ The NOT operator display record with the condition isn’t true.
Question 5: Display record from Client_Master_5B where balance due is greater than 500
and whose doesn’t belong to Delhi.

31
Hemang Goel 02361188820

Assignment 6
Date: 03-10-2022

The SQL UPDATE commands


The UPDATE statement is used to modify the existing records in a table.

Syntax
Update table_name

SET column 1 =value 1, column 2 = value 2,


Where condition;

Question 1: Update the city to Noida of those client whose balance is greater than 5000.

32
Hemang Goel 02361188820

Question 2: Increase the balance due of all clients by 20%.

33
Hemang Goel 02361188820

Question 3: Update the customer’s name Vijay and City to Kanpur where personal ID is 105.

34
Hemang Goel 02361188820

Question 4: Update all balance due to 10000 in Client_Master.

35
Hemang Goel 02361188820

Question 5: Delete the record from table where City is Noida, State is UP and Client Number
is 101 or 102. OR as per your client_no.

36
Hemang Goel 02361188820

37
Hemang Goel 02361188820

Assignment 7
Date: 06-10-2022

SQL LIKE operator


The LIKE operator is used in your where clause to search for specified pattern in a column.

There are two wildcards used in consumption in the like operators.


(i) “%” : The percentage sign represent 0, 1, or multiple characters.
(ii) “_” : The underscore sign represents single characters.

Syntax
Select column1, column2,..
From table_name

Where condition like pattern;

Question 1: To display the name of client whose name start with character A.

38
Hemang Goel 02361188820

Question 2: Display the name of client whose name second character is ‘h’.

Question 3: Find the name of client whose name end with “a”.

39
Hemang Goel 02361188820

Question 4: Find the name of client that have “or” in any position.

Question 5: Find the name of client whose name 4th character is “r”.

40
Hemang Goel 02361188820

Question 6: Find the name of client whose name start with “A” and have at least 4 characters
in length.

Question 7: Find the names of client whose name start with “A” and end with “o”.

41
Hemang Goel 02361188820

Assignment 8
Date: 06-10-2022

The SQL IN operator


The IN operator allow to specify multiple values in where clause.

Note: The IN operator in shorthand for multiple OR condition.

Syntax
Select column_names
From table_names
Where column_names IN (Value 1, Value 2, …..);

Question 1: Select details of all customers that are located in Delhi, Noida, Ghaziabad.

42
Hemang Goel 02361188820

Question 2: Select details of all customers that are not located in Delhi, Noida, Ghaziabad.

SQL BETWEEN operators


The BETWEEN operators select values within a given range the values can be the text,
number, dates.

The BETWEEN operators is uses ‘begining and end value’ are included.

Syntax
Select column_names
From table_names

Where column_names between value 1 and value 2;

43
Hemang Goel 02361188820

Question 3: To show the details of all clients whose balance whose balance due between
1000 & 6000.

Question 4: To show the details of all clients whose balance whose balance not due between
1000 & 6000

44
Hemang Goel 02361188820

Question 5: Select all clients with Balance due between 1000& 5000 in addition don’t show
with the city name Noida and Ghaziabad.

45
Hemang Goel 02361188820

Assignment 9
Date: 10-10-2022

SQL ALTER TABLE STATEMENT


The ALTER table statement is used to alt, delete or modify columns in an existing table.
The alter table statement is also used to had drop various constraints on an existing table.

ALTER TABLE- ADD column


To add a column in a table

Syntax
Alter table<table_name>
Add<column_name><Data types>;

Question 1: To add a new column mobile number into the table Client_Master.

46
Hemang Goel 02361188820

Question 2: Update mobile number for all existing client number into the Client_Master
table.

47
Hemang Goel 02361188820

48
Hemang Goel 02361188820

49
Hemang Goel 02361188820

50
Hemang Goel 02361188820

51
Hemang Goel 02361188820

Question 3: To show the details of all client whose name second character is p and who
belongs to Delhi or Noida, where balance due is greater than 500.

52
Hemang Goel 02361188820

ALTER TABLE- Drop column


To delete a column in a table.

Syntax
Alter table<table_name>
Drop column<column_name>;

Question 4: Drop the column mobile number from Client_Master table.

53
Hemang Goel 02361188820

Question 5: Drop the column balance due from Client_Master table.

54
Hemang Goel 02361188820

Question 6: Add the column baldue in the table Client_Master_5B.

55
Hemang Goel 02361188820

56
Hemang Goel 02361188820

57
Hemang Goel 02361188820

58
Hemang Goel 02361188820

59

You might also like