Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Different Types of Commands in SQL

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

INTRODUCTION

Different types of commands in SQL:


A). DDL commands: - To create a database objects.
1. The Create Table Command.
2. Modifying the structure of tables.
3. Dropping a column from a table.
4. Modifying existing columns.
5. Renaming :
i) renaming the table.
ii) renaming the column.
6. Truncating the tables.
7. Destroying tables.
B).DML commands: - To manipulate data of a database objects.
1. Inserting Data into Tables.
2. Delete operations.
3. Updating the contents of a table.
4. Types of data constrains.
i) not null constraint at column level.
ii) unique constraint.
iii) unique constraint at table level.
iv) primary key constraint at column level
v) primary key constraint at table level.
vi) foreign key constraint at column level.
vii) foreign key constraint at table level
viii) check constraint
ix) check constraint constraint at table level.
C).DQL command: - To retrieve the data from a database.
1. Viewing data in the tables.
2. Filtering table data
i) Selected columns and all rows.
ii) Selected rows and all columns.
iii) Selected columns and selected rows.
3. Sorting data in a table.
D). DCL/TCL commands: - To control the data of a database.
1. Grant privileges using the GRANT statement
2. Revoke permissions using the REVOKE statement

COMMANDSto discuss :
1. create table
2. insert into
3. Alter table --- add, rename, modify columns
4. Update ---using & not using where
5. Select--- all columns and some columns
6. Delete ---all rows and some rows
7. Rename ---table
8. drop table
9. FLASHBACK TABLE
10.drop table customer2 purge

11. copy the structure and data from another table


12. copy only table without data
13. insert data from other table
14. delete, drop and truncate

PROBLEMS

customer (cust_id ,cust_fname ,cust_lname ,territory ,cred_lmt, mngr_id , marital_status ,sex


,income)
1. Create and insert given data in table customer.
2. Alter table and Add column stay_from_year
3. Set value of stay_from_year as 2001 for Italy/America and 2003 otherwise
4. Display credit limit attribute for America
5. Delete the record corresponding to Meg Sen
6. Show all attributes for Italy// Show all data in the territory Italy
7. If territory is India and status is Single set value of credit to 7000
8. Rename cust_fname to first_name
9. Rename cust_lname to last_name
10. Create table cust1 from the old table customer(copy structure as well as data using CTAS
statement).
11. Create tables cust2 without values of cust1 using CTAS statement.
12. Create tables cust3 with attributes cust_id,cust_fname,cust_lname,income from old customer
table
only 5 rows.(using CTAS statement).
13. Create tables cust4 with attributes name customer_id,firstname,lastname, income from old
customer
table(using CTAS statement).
14. Drop column income from cust1.
15. Rename table cust1 to cust_one
16. Insert values into cust2 table from customer table
17. Insert values into cust3 table with attributescust_ id, f_name, l_name,Income from customer
table where income > 50000
18. alter the table cust4 change cust id to varchar(6) and income to number(5)
19. Add new attribute mngr_name to cust4 and insert 5 records
20. Add attribute territory to cust4
21. Drop table cust3 and then bring it back.

22. Increase the size of the column custid by 5.

23. Suppose the customer with id no C63 has changed her last name & now it is just same as the
customer with id no C68.

24. Replace the last name of customer with cid “C68” with the last name of customer with id
“C63”

/*Update customer set lname=(select lname from customer where cid=C63) where cid=C68.*/

25. Display the records where territory=America &crd_lmt=25000.

26. Display the records of all Indian customers whose income>20000.

27. Display the name of the customer having crd_lmt between 2000 and 7000.

28. Display the records of the customers having income 20000,24000,300,4500 using only one
query.

29. Display the records in ascending order of first name

30. Display the records in descending order of income.

31. Insert a duplicate record and display all the records.

32. Suppose your friend wants to select a name from the names of the customers. Show the
different names of the student.

You might also like