Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- show databases;
- use lab2;
- create table employee(id int,firstname varchar(100),lastname varchar(100),address varchar(100),city varchar(100));
- insert into employee(id,firstname,lastname,address,city) values(101,'John','Kumar','Lane 1','Bengaluru');
- insert into employee(id,firstname,lastname,address,city) values(102,'King','Singh','Lane 2','Bengaluru');
- insert into employee(id,firstname,lastname,address,city) values(103,'Ben','Sharma','Lane 3','Bengaluru');
- select * from employee;
- alter table employee add column salary int;
- select * from employee;
- set sql_safe_updates = 0;
- update employee set salary = case when id=101 then 10000 when id=102 then 20000 when id=103 then 30000 else salary end;
- select * from employee;
- alter table employee drop column salary;
- select * from employee;
- alter table employee rename column city to jagah;
- select * from employee;
- rename table employee to gulaam;
- select * from gulaam;
- Output:
- Output:
- +------+-----------+----------+---------+-----------+
- | id | firstname | lastname | address | city |
- +------+-----------+----------+---------+-----------+
- | 101 | John | Kumar | Lane 1 | Bengaluru |
- | 102 | King | Singh | Lane 2 | Bengaluru |
- | 103 | Ben | Sharma | Lane 3 | Bengaluru |
- +------+-----------+----------+---------+-----------+
- +------+-----------+----------+---------+-----------+--------+
- | id | firstname | lastname | address | city | salary |
- +------+-----------+----------+---------+-----------+--------+
- | 101 | John | Kumar | Lane 1 | Bengaluru | NULL |
- | 102 | King | Singh | Lane 2 | Bengaluru | NULL |
- | 103 | Ben | Sharma | Lane 3 | Bengaluru | NULL |
- +------+-----------+----------+---------+-----------+--------+
- +------+-----------+----------+---------+-----------+--------+
- | id | firstname | lastname | address | city | salary |
- +------+-----------+----------+---------+-----------+--------+
- | 101 | John | Kumar | Lane 1 | Bengaluru | 10000 |
- | 102 | King | Singh | Lane 2 | Bengaluru | 20000 |
- | 103 | Ben | Sharma | Lane 3 | Bengaluru | 30000 |
- +------+-----------+----------+---------+-----------+--------+
- +------+-----------+----------+---------+-----------+
- | id | firstname | lastname | address | city |
- +------+-----------+----------+---------+-----------+
- | 101 | John | Kumar | Lane 1 | Bengaluru |
- | 102 | King | Singh | Lane 2 | Bengaluru |
- | 103 | Ben | Sharma | Lane 3 | Bengaluru |
- +------+-----------+----------+---------+-----------+
- +------+-----------+----------+---------+-----------+
- | id | firstname | lastname | address | jagah |
- +------+-----------+----------+---------+-----------+
- | 101 | John | Kumar | Lane 1 | Bengaluru |
- | 102 | King | Singh | Lane 2 | Bengaluru |
- | 103 | Ben | Sharma | Lane 3 | Bengaluru |
- +------+-----------+----------+---------+-----------+
- +------+-----------+----------+---------+-----------+
- | id | firstname | lastname | address | jagah |
- +------+-----------+----------+---------+-----------+
- | 101 | John | Kumar | Lane 1 | Bengaluru |
- | 102 | King | Singh | Lane 2 | Bengaluru |
- | 103 | Ben | Sharma | Lane 3 | Bengaluru |
- +------+-----------+----------+---------+-----------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement