The document provides a comprehensive guide on creating and managing a database named 'student' using SQL commands. It includes steps for creating a database, tables, inserting and updating records, altering table structures, and querying data. Additionally, it features examples of queries for other tables like 'Student' and 'Item', demonstrating various SQL operations such as selection, insertion, and updates.
The document provides a comprehensive guide on creating and managing a database named 'student' using SQL commands. It includes steps for creating a database, tables, inserting and updating records, altering table structures, and querying data. Additionally, it features examples of queries for other tables like 'Student' and 'Item', demonstrating various SQL operations such as selection, insertion, and updates.
Create database student; 2. TO SHOWING ALL DATABASE; Show databases; 3. GOING INTO DATABASE FOR CREATING TABLE AND OTHER OPERATION Use student; 4. FOR CREATE TABLE; Create table student_details (srno int(3), name char(10), address varchar (20)); 5. FOR INSERTING VALUES INTO TABLE: Insert into student_details values(01, ‘mohit’ , ‘naharpur’); Insert into student_details values(02, ‘rohit’ , ‘rohini’); Insert into student_details values(03, ‘sagar’ , ‘badli’); Insert into student_details values(04, ‘aniket’ , ‘jhangirpuri’); Insert into student_details values(05, ‘nihal’ , ‘budhvihar’); 6. FOR SHOWING DESCRIPTION OF TABLE desc student_details; Field Type Null Key Default Extra Srno Int(3) Yes Null Name Char(10) Yes Null address Varchar(20) Yes Null
alter table student_details add ( aadhar int(16)); 9. FOR SHOWING AFTER ADDING NEW ATTRIBUTE: Select * from student_details; Srno Name Address Aadhar 1 Mohit Naharpur Null 2 Rohit Rohini Null 3 Sagar Badly Null 4 Aniket Jhangirpuri Null 5 nihal budhvihar Null
10. ADDING VALUES INTO FIELD
update student_details set aadhar = 12345678941 where name = ‘ mohit’; update student_details set aadhar = 45678912345 where name = ‘ rohit’; update student_details set aadhar = 96541235478 where name = ‘ sagar’; update student_details set aadhar = 96478456612 where name = ‘ aniket’; update student_details set aadhar = 65897455612 where name = ‘ nihal’; 11. FOR UPDATE VALUES INTO FIELD update student_details set name = sanjay where name = ‘ mohit’; Srno Name Address Aadhar 1 Sanjay Naharpur Null 12. FOR SHOWING VALUES AFTER ADDING VALUES INTO FIELD Srno Name Address Aadhar 1 Mohit Naharpur 12345678941 2 Rohit Rohini 45678912345 3 Sagar Badly 96541235478 4 Aniket Jhangirpuri 96478456612 5 nihal budhvihar 65897455612
13. FOR DELETING ATTRIBUTE;
Alter table student_details drop aadhar; Srno Name Address 1 Mohit Naharpur 2 Rohit Rohini 3 Sagar Badly 4 Aniket Jhangirpuri 5 nihal budhvihar
14. QUERY FOR SEARCHING FULL DETAILS OF SRNO is 4:
Select * from student_details where srno = 4; 4 Aniket Jhangirpuri
15. QUERY FOR SEARCHING FULL DETAILS OF ADDRESS is budhvihar
Select * from student_details where address = ‘budhvihar’; 5 nihal budhvihar
16. QUERY FOR SEARCHING FULL DETAILS OF Name is mohit
Select * from student_details where name = ‘mohit’; 1 Mohit Naharpur
17. QUERY FOR DESCENDING ORDER
Select * from tablename order by name;
QUESTION AND ANSWERS:
1. Write the queries for the following table: Student Admno Name Class House 1001 Sonam 9 Blue 1002 Ravi 10 Yellow 1003 Poonam 10 Green
a. To display the entire table:
Select * from Student b. Display the list of students whose house colour is blue: Select * from Student where House= ‘Blue’; c. Display the admission number of students whose house colour is green. Select admno from student where house = ‘Yellow’; d. To view record of admission number in ascending order Select * from Student order by admno asc; e. To view record of admission number in descending order Select * from Student order by admno; f. To display the record of class 10 Select * from Student where class = 10; g. Display the class of Ravi Select Class from Student where name = ‘Ravi’; h. Insert the given record : 1004, ‘Aman’, 11, ‘Blue’; Insert into Student values (1004, ‘Aman’, 11, ‘Blue’);
a. Write a query to insert a new record 15, ‘Pencil’, 20,10
Insert into Item values (15, ‘Pencil’, 20,10); b. Write a query to display detail of items whose quantity is more than 10. Select * from Item where Qty > 10; c. Write a query to change the quantity of item number 13 to 25. Update Item set itemno = 25 where Itemno = 13; d. Display the total amount of each item. The amount must be calculated as the price multiplied by quantity of each item. Select Price* Qty from Item; e. Display the name of item whose price is 10. Select Iname from Item where price = 10; f. Display all the record in ascending order of price. Select * from Item order by Price asc. g. Identify the primary key from table Item; Itemno h. Write the suitable datatype of field ‘Iname’ Char or Varchar i. Write a query to increase price of all item by Rs 2. Update Item set price = price +2;