SQL in 4 Hours
SQL in 4 Hours
#Null is not allowed in Primary key field; Null is allowed in Unique field.
1. create table stdmaster
( AdmNo char(10) primary key,
admdate date,
name varchar(20) not null,
email varchar(30) unique,
class int(2), section char(1), rno int(2) );
2. desc stdmaster;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| AdmNo | char(10) | NO | PRI | NULL | |
| admdate | date | YES | | NULL | |
| name | varchar(20) | NO | | NULL | |
| email | varchar(30) | YES | UNI | NULL | |
| class | int(2) | YES | | NULL | |
| section | char(1) | YES | | NULL | |
| rno | int(2) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
5. desc stdmaster;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| AdmNo | char(10) | YES | | NULL | |
| admdate | date | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
| class | int(2) | YES | | NULL | |
| section | char(1) | YES | | NULL | |
| rno | int(2) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
36. select admno, admdate, email from stdmaster where name like 'A%';
37. select name from stdmaster where name not like '%a';
38. select admno, admdate, email from stdmaster where email not like '_%@%.%_';
39. select admno, admdate, email from stdmaster where email like '%@%@%';
40. select * from stdmaster where section between 'B' and 'C';
41. select * from stdmaster;
+-----------+------------+----------+--------+-------+---------+------+
| AdmNo | admdate | name | email | class | section | rno |
+-----------+------------+----------+--------+-------+---------+------+
| 200700001 | 2007-04-01 | Abhay | [email protected] | 1 | A | 1 |
| 200700002 | 2007-04-01 | Azhar | [email protected] | 1 | A | 2 |
| 200800007 | 2008-04-11 | Sukhdeep | [email protected] | 3 | B | 11 |
| 200800009 | 2008-04-13 | Benita | [email protected] | 3 | C | 4 |
| 200800012 | 2008-06-13 | Bharat | [email protected] | 5 | B | 6 |
+-----------+------------+----------+--------+-------+---------+------+
42. alter table stdmaster add fee float;
43. select * from stdmaster;
44. update stdmaster set fee=class*100;
45. select * from stdmaster;
46. select admno, fee, fee*0.05 as fine from stdmaster;
47. select max(fee),min(fee),avg(fee),count(fee),sum(fee) from stdmaster;
48. select max(email),min(email),avg(email),count(email),sum(email) from stdmaster;
49. select max(fee),min(fee),avg(fee),count(fee),sum(fee) from stdmaster where class=5;
50. select min(fee)*2 as "Lowest Sch", max(fee)*2 as "Highest Sch" from stdmaster;
Hour-3
Create a table HouseAct with the following structure:
67. select sm.admno, name, house, activity from stdmaster sm, houseact ha where
sm.admno=ha.admno;
68. select stdmaster.admno, name, class, section, activity from stdmaster, houseact where
stdmaster.admno=houseact.admno;
69. select stdmaster.admno, name, class, section, activity from stdmaster, houseact where
stdmaster.admno=houseact.admno and activity = 'dance';