0% found this document useful (0 votes)
141 views

Exercise 1: DDL Commands: SP - Help

1. The document describes SQL commands to create, alter, insert, select, and drop a table called employee. It includes commands to add and drop columns, modify columns, insert records, display records, rename tables, and delete all records. 2. It also provides exercises to create a Student table, insert records, and perform queries to display student details meeting certain criteria like department, total marks, percentage, etc. 3. Additional exercises are given to write SQL queries on a customer table to filter and display records based on conditions on city and grade.

Uploaded by

KÖWSHÏK R
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
141 views

Exercise 1: DDL Commands: SP - Help

1. The document describes SQL commands to create, alter, insert, select, and drop a table called employee. It includes commands to add and drop columns, modify columns, insert records, display records, rename tables, and delete all records. 2. It also provides exercises to create a Student table, insert records, and perform queries to display student details meeting certain criteria like department, total marks, percentage, etc. 3. Additional exercises are given to write SQL queries on a customer table to filter and display records based on conditions on city and grade.

Uploaded by

KÖWSHÏK R
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Exercise 1:

DDL Commands
1. Create a table employee (ename(30 chars), eid, edesignation(20 chars), ecity)
Perform the following queries
1.Describe the fields of the table. (hint: use sp_help command)
--create table employee(ename varchar(30), eid int, edesgn varchar(10), ecity
varchar(10));
sp_help employee;

2.Add a new field named salary to the table and it must contain some values.
--create table employee(ename varchar(30), eid int, edesgn varchar(10), ecity
varchar(10));
--sp_help employee;
--alter table employee add salary float;
select*from employee;

3.Modify the field edesignation so that it can accept upto 30 characters.


--alter table employee alter column edesgn varchar(30);
--sp_help employee;
4.Insert 10 employee records.
--insert into employee2 values('ram', 100, 'student', 'satrapati', 1500);
--insert into employee2 values('krish', 101, 'prof.', 'marutur', 16000);
--insert into employee2 values('shiv', 102, 'admin', 'rjpm', 17000);
--insert into employee2 values('rudra', 103, 'CEO', 'tnvl', 18000);
--insert into employee2 values('sakthi', 104, 'student', 'snkl', 19000);
--insert into employee2 values('jrama', 105, 'student', 'maruthur', 15000);
--insert into employee2 values('kowshi', 106, 'student', 'madurai', 17000);
--insert into employee2 values('sudha', 107, 'student', 'rjpm', 15000);
--insert into employee2 values('kali', 108, 'student', 'kalupati', 17000);
--insert into employee2 values('vicky', 109, 'prof', 'tnvl', 18000);
select * from employee2;

5.Display the employee details.


6.Drop a column salary.

--alter table employee2 drop column salary;


select * from employee2;

7.Rename the table. (hint: command sp_rename):


sp_rename employee3,employei;

8.Delete all employee record from the table. (hint: use delete/truncate command)
--truncate table employee2;
select * from employee2;
9.Drop the table.
--sp_rename employee3,employei;
--drop table employei;

DML Commands
1. Create the following tables
Student (Rollno, Name, Deptname, Marks (of 4 Subjects), Total, Percentage.
Insert 10 student details.
a) Display the Student details.
b) Display the student names who got total greater than 300
c) Display the CSE department student names.
d) Display the student detail whose department is “it” and also percentage is greater than
or equal to 75.
e) Find the student details whose department is in Civil, Mech.
f) Select regno, name, grade, department, percentage of all students
g) Sort the student name in ascending order and descending order.
h) Drop the column rollno.

Additional Exercises

Table name: customer

customer_id | cust_name | city | grade | salesman_id


------------+----------------+------------+-------+------------
3002 | Nick Rimando | New York | 100 | 5001
3007 | Brad Davis | New York | 200 | 5001
3005 | Graham Zusi | California | 200 | 5002
3008 | Julian Green | London | 300 | 5002
3004 | Fabian Johnson | Paris | 300 | 5006
3009 | Geoff Cameron | Berlin | 100 | 5003
3003 | Jozy Altidor | Moscow | 200 | 5007
3001 | Brad Guzan | London | | 5005
 Write a query to display all customers with a grade above 100.   
 Write a query statement to display all customers in New York who have a grade value
above 100.    
 Write a SQL statement to display all customers, who are either belongs to the city New
York or had a grade above 100.    
 Write a SQL statement to display all the customers, who are either belongs to the city
New York or not had a grade above 100.    
 Write a SQL query to display those customers who are neither belongs to the city New
York nor grade value is more than 100.    

You might also like