You are on page 1of 4

1. Create a table and insert data.

create database studentdb;


use studentdb;
create table student123(sid int,sname varchar(30),marks int);
desc student123;

Implement the following SQL commands on the student table:

 ALTER table to add new attributes/ modify data type /


drop attribute
1. alter table student123 add primary key(sid);
// the above line is for adding constraint i.e., primary
key
2. alter table student123 add(total int);
// the above line is for adding new attribute
3. alter table student123 modify total float(3,2);
//the above line is to modify data type of a
column

4. alter table student123 drop total;


//the above line is to drop column
 INSERT data into the table.
insert into student123 values(1,'ABC',99);
insert into student123 values(2,'PQR',89);
insert into student123 values(3,'PQR',86);
 Display data by using SELECT command
select * from student123;

 UPDATE table to modify data


update student123 set sname='XYZ' where sid=3;

 ORDER By to display data in ascending/ descending order.


select * from student123 order by sid desc;

select * from student123 order by sname asc;

You might also like