0% found this document useful (0 votes)
14 views2 pages

GR 12

Project

Uploaded by

barwaliyaheer25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

GR 12

Project

Uploaded by

barwaliyaheer25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Create table Student12(

Rollno integer Not null Auto_increment primary key,


Name varchar(20) not null,
Gender char(1),
Marks integer(11),
DOB date );

DESC Student12; (Viewing a Table structure)


//To open database
USE Student12;

//To display all the tables in Database


SHOW Tables;

//DDL Command: CREATE, DROP


//DML Command:Insert, Update

insert into Student12(Name,Gender,Marks,DOB) values ('Harish','M',180,'2000-06-


19');

alter table Student12 MODIFY Name varchar(30);

alter table Student12 CHANGE City State varchar(20); (Renaming column)

alter table Student12 DROP (State); (Removing column)

drop table Student12;

alter table Student12 ADD(City char(10) default "Delhi"); (Add Column with
default value)

insert into Student12(Name,Gender,Marks,DOB,City) values ('Lakshman','M',180,'2000-


06-19','Ayodhya');

alter table Student12 ADD Primary key (Rollno); (Add primary key)

alter table Student12 DROP primary key; (delete primary key)

//Update
UPDATE Student12 SET Marks=90 where Rollno=5;

UPDATE Student12 SET Marks=70, DOB='1998-08-11' where Name="Payal";

//Updating NULL value


UPDATE Student12 set Marks=NULL where Rollno=9;

//Updating using an expression or formula


UPDATE Student12 SET Marks=Marks+10 where (Rollno=5 or Rollno=10);

//Updating all rows using an expression or formula


UPDATE Student12 SET Marks = Marks+5;

//SQL TRUNCATE Statement


TRUNCATE Table Student12;

//varchar(20) (Manav) char(20)Manav (How many characters occupied in varchar and


char)

//Max and Min function


select max(sal) from Student12;
select min(sal) from Student12;

//SQL queries
1. Display Students Rollno, name, gender and matrks
Ans. select Rollno, name,Gender, Marks from Student12;

2. List the different name of the students


Ans. select distinct Name from Student12;

3. Display Rollno, name and marks with greater than 50 and less than 100.
Ans. select Rollno, Name, Marks from Student12 where Marks>50 AND Marks<100;

4. Display all the data with marks 30 or 40.


Ans. select * from Student12 where Marks=30 OR Marks=40.

5. List all the student data which marks is null.


Ans. select * from Students12 where Marks is NULL;

//Group by Clause
alter table Student12 ADD(sal decimal(7,2));

select max(sal) from Student12 group by Rollno;

//Cardnality: Total number of records

//Domain:

You might also like