0% found this document useful (0 votes)
6 views6 pages

SQL Programming

The document contains a series of SQL tasks including creating and manipulating a Student and Customer table. It includes queries for inserting data, updating records, selecting specific information, and performing aggregate functions. The document also demonstrates how to alter table structures and filter results based on conditions.

Uploaded by

debbarmasuham526
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)
6 views6 pages

SQL Programming

The document contains a series of SQL tasks including creating and manipulating a Student and Customer table. It includes queries for inserting data, updating records, selecting specific information, and performing aggregate functions. The document also demonstrates how to alter table structures and filter results based on conditions.

Uploaded by

debbarmasuham526
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

SQL PRACTICAL TASK

1. Write a sql query to create a student table with the fields namely Student id,
Student name, Date of Birth, Marks of English, Marks of Math, and Marks of Hindi.

create table Student(Stu_id integer, Sname varchar(30),DOB date,eng integer,


maths integer, hindi integer)

Output: SQL command executed successfully.

2, Create a SQL query for inserting data in Student table.

insert into Student values(01,'NIharika','10/03/2005',65,78,93)

Output: SQL command executed successfully.

insert into Student values(02,'Piyali','13/10/2006',57,65,88)

Output: SQL command executed successfully.

insert into Student values(03,'Manoj','25/06/2005',76,67,89)

Output: SQL command executed successfully.

insert into Student values(03,'Rahul','21/07/2006',56,43,89)

Output: SQL command executed successfully.

insert into Student values(05,'Vivek','20/11/2007',67,53,87)

Output: SQL command executed successfully.

3. Display the content of the whole Student table

Select * from Student.

Output

Stu_i en mat hin


Sname DOB
d g hs di
NIharik 10/03/20
1 65 78 93
a 05
13/10/20
2 Piyali 57 65 88
06
25/06/20
3 Manoj 76 67 89
05
3 Rahul 21/07/20 56 43 89
Stu_i en mat hin
Sname DOB
d g hs di
06
20/11/20
5 Vivek 67 53 87
07

4. Write an SQL query to update the Student id of Rahul as it is wrongly inserted.


So change the Stu_id =4

update Student set Stu_id=4 where Sname='Rahul'

Output

Stu_i Snam en mat hin


DOB
d e g hs di
NIhari 10/03/2
1 65 78 93
ka 005
13/10/2
2 Piyali 57 65 88
006
25/06/2
3 Manoj 76 67 89
005
21/07/2
4 Rahul 56 43 89
006
20/11/2
5 Vivek 67 53 87
007

5. Write a SQL query to add new column in the Student Table.

Alter table Student add Address Varchar(50)

Stu_i en mat hin Addre


Sname DOB
d g hs di ss
NIharik 10/03/20
1 65 78 93
a 05
13/10/20
2 Piyali 57 65 88
06
25/06/20
3 Manoj 76 67 89
05
21/07/20
4 Rahul 56 43 89
06
20/11/20
5 Vivek 67 53 87
07
6. Write a SQL query to delete the newly added column ‘Address’ in the table
Student.

ALTER TABLE Student

DROP COLUMN Address;

Output: SQL command executed successfully.

7. Write a SQL query to select the name of the student who obtained minimum
marks in Eng.

SELECT Sname, MIN(Eng) FROM Student

Output

Snam MIN(En
e g)
Rahul 56

8. Write a SQL query to select the name of the student who obtained Maximum
marks in Hindi.

Snam Max(Hin
e di)
NIharik
93
a

9. Write a SQL query to find the sum of all the Student’s English Marks.

SELECT SUM(eng) FROM Student

Output:

TOTAL
321

{**Note- ‘Here, AS is used to replace the default column name}


10. Write a SQL query to Convert any line of text to Lowercase

SELECT LOWER('SHISHU BIHAR') AS LOWERCASE;

LOWERCASE
shishu bihar

11. Write a SQL query to Convert any line of text to Upper Case

SELECT UPPER('shishu bihar') AS UPPERCASE;

UPPERCASE
SHISHU BIHAR

Write a sql query to create a Customer table with the fields namely Customer id,
Customer name, Salary, State.

create table Customer(Cust_id integer, Cname varchar(30),Salary Decimal, State


varchar(15));

Output: SQL command executed successfully.

Create a SQL query for inserting data in Customer table.

insert into customer values(10,'Ayush',5000.00,'tripura');

Output: SQL command executed successfully.

insert into customer values (11, 'Ishan',7000.00,'tripura');

Output: SQL command executed successfully.

insert into customer values (12, 'Rahul',10000.00,'Gujrat');

Output: SQL command executed successfully.

insert into customer values (13, 'Sania',8000.00,'Rajasthan');

Output: SQL command executed successfully.

12. Write a SQL to display the salary between 8000 to 10000 from customer table
Select * from customer where salary between 8000.00 and 10000.00;

Output:

Cust_i Cnam Salar


State
d e y
1000
12 Rahul Gujrat
0
Rajasth
13 Sania 8000
an

13. Write a SQL query to display the person’s details whose salary not between
8000 to 10000 from customer table.

Select * from customer where salary not between 8000.00 and 10000.00;

Output

Cust_i Cnam Salar


State
d e y

Ayus tripur
10 5000
h a
tripur
11 Ishan 7000
a

14. Write a SQL query to display state name starts with ‘t’

Select * from customer where state like 't%';

Output:

Cust_i Cnam Salar Stat


d e y e
tripur
10 Ayush 5000
a
tripur
11 Ishan 7000
a
15. Write a SQL query to group by customer state and count customer id under
the same state

Select count(Cust_id),state from customer group by state;

Output

count(Cust_
State
id)
1 Gujrat
Rajasth
1
an
2 tripura

16. Write a SQL query to update salary of a customer with customer id=12

update customer set salary=9000.00 where custid=12;

Output: SQL command executed successfully.

You might also like