List of Table Operations in SQL [1. CREATE, 2. INSERT,
3.UPDATE, 4. ALTER, 5. DELETE, 6. DROP, 7. TRUNCATE ]
1.
CREATE : To define a new Table.
2.
INSERT : Add rows to the table.
3.
UPDATE : Modify existing rows in the
table.
4.
ALTER : Modify the structure of the
table.
5.
DELETE : Remove Rows from the table.
6.
DROP : Removes the entire table.
7.
TRUNCATE : Removes the all rows of the
table but it keeps the table structure.
1> CREATE : To define a new Table.
CREATE
TABLE jobs ( |
job_id INT PRIMARY KEY, |
job_title VARCHAR(100), |
job_description TEXT, |
min_salary DECIMAL(10, 2), |
max_salary DECIMAL(10, 2) |
); |
2 INSERT : Add rows to the table
VALUES
(100, ‘Manager’,
‘Manage the Team', 800000, 1500000);
3> UPDATE : Modify existing rows in the
table.
UPDATE jobs SET min_salary = 100000
WHERE job_id = 100;
Note : It will change the min salary to 100000 from 800000 for the job_id 100.
4> ALTER : Modify the structure of the table.
ALTER TABLE jobs ADD COLUMN dept_id INT;
5> DELETE : Remove Rows from the table
DELETE FROM jobs WHERE job_id = 100;
6> DROP : Removes the entire table.
DROP TABLE jobs;
7> TRUNCATE : Removes the all rows of the
table but it keeps the table structure
TRUNCATE TABLE jobs;
Note : > It removes all rows from the
table.
Ø It
retains the Table Structure
Ø It
is faster then DELETE statement
No comments:
Post a Comment