Advertisement
GamerBhai02

DBMS EXP 2

Mar 17th, 2025 (edited)
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 3.31 KB | Source Code | 0 0
  1. show databases;
  2. use lab2;
  3. create table employee(id int,firstname varchar(100),lastname varchar(100),address varchar(100),city varchar(100));
  4. insert into employee(id,firstname,lastname,address,city) values(101,'John','Kumar','Lane 1','Bengaluru');
  5. insert into employee(id,firstname,lastname,address,city) values(102,'King','Singh','Lane 2','Bengaluru');
  6. insert into employee(id,firstname,lastname,address,city) values(103,'Ben','Sharma','Lane 3','Bengaluru');
  7. select * from employee;
  8. alter table employee add column salary int;
  9. select * from employee;
  10. set sql_safe_updates = 0;
  11. update employee set salary = case when id=101 then 10000 when id=102 then 20000 when id=103 then 30000 else salary end;
  12. select * from employee;
  13. alter table employee drop column salary;
  14. select * from employee;
  15. alter table employee rename column city to jagah;
  16. select * from employee;
  17. rename table employee to gulaam;
  18. select * from gulaam;
  19.  
  20. Output:
  21. Output:
  22.  
  23. +------+-----------+----------+---------+-----------+
  24. | id   | firstname | lastname | address | city      |
  25. +------+-----------+----------+---------+-----------+
  26. |  101 | John      | Kumar    | Lane 1  | Bengaluru |
  27. |  102 | King      | Singh    | Lane 2  | Bengaluru |
  28. |  103 | Ben       | Sharma   | Lane 3  | Bengaluru |
  29. +------+-----------+----------+---------+-----------+
  30. +------+-----------+----------+---------+-----------+--------+
  31. | id   | firstname | lastname | address | city      | salary |
  32. +------+-----------+----------+---------+-----------+--------+
  33. |  101 | John      | Kumar    | Lane 1  | Bengaluru |   NULL |
  34. |  102 | King      | Singh    | Lane 2  | Bengaluru |   NULL |
  35. |  103 | Ben       | Sharma   | Lane 3  | Bengaluru |   NULL |
  36. +------+-----------+----------+---------+-----------+--------+
  37. +------+-----------+----------+---------+-----------+--------+
  38. | id   | firstname | lastname | address | city      | salary |
  39. +------+-----------+----------+---------+-----------+--------+
  40. |  101 | John      | Kumar    | Lane 1  | Bengaluru |  10000 |
  41. |  102 | King      | Singh    | Lane 2  | Bengaluru |  20000 |
  42. |  103 | Ben       | Sharma   | Lane 3  | Bengaluru |  30000 |
  43. +------+-----------+----------+---------+-----------+--------+
  44. +------+-----------+----------+---------+-----------+
  45. | id   | firstname | lastname | address | city      |
  46. +------+-----------+----------+---------+-----------+
  47. |  101 | John      | Kumar    | Lane 1  | Bengaluru |
  48. |  102 | King      | Singh    | Lane 2  | Bengaluru |
  49. |  103 | Ben       | Sharma   | Lane 3  | Bengaluru |
  50. +------+-----------+----------+---------+-----------+
  51. +------+-----------+----------+---------+-----------+
  52. | id   | firstname | lastname | address | jagah     |
  53. +------+-----------+----------+---------+-----------+
  54. |  101 | John      | Kumar    | Lane 1  | Bengaluru |
  55. |  102 | King      | Singh    | Lane 2  | Bengaluru |
  56. |  103 | Ben       | Sharma   | Lane 3  | Bengaluru |
  57. +------+-----------+----------+---------+-----------+
  58. +------+-----------+----------+---------+-----------+
  59. | id   | firstname | lastname | address | jagah     |
  60. +------+-----------+----------+---------+-----------+
  61. |  101 | John      | Kumar    | Lane 1  | Bengaluru |
  62. |  102 | King      | Singh    | Lane 2  | Bengaluru |
  63. |  103 | Ben       | Sharma   | Lane 3  | Bengaluru |
  64. +------+-----------+----------+---------+-----------+
Tags: exp2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement