DCL, DML, DQL commands
DCL, DML, DQL commands
Week-1
b. DROP: It is used to delete both the structure and record stored in the
table.Syntax DROP TABLE table_name;
Example
DROP TABLE EMPLOYEE;
Page No:
Output:
b. ALTER: It is used to alter the structure of the database. This change could be
either to modify the characteristics of an existing attribute or probably to add a
new attribute.
Syntax:
To add a new column in the table
ALTER TABLE table_name ADD column_name COLUMN-definition; To modify
existing column in the table:
ALTER TABLE table_name RENAME (column_definitions....);
To rename existing column name in the table:
ALTER TABLE table_name RENAME old_column_name to new-
column_name;
EXAMPLE
20ALTER TABLE STU_DETAILS MODIFY (NAME VARCHAR(20));
Output:
c. TRUNCATE: It is used to delete all the rows from the table and free the
space containing the table.
Syntax:
TRUNCATE TABLE table_name;
Example:
TRUNCATE TABLE EMPLOYEE;
Output:
o DELETE
For example:
INSERT INTO students (Name, Subject) VALUES ("Sonoo", "DBMS");
Output:
For example:
UPDATE students
SET User_Name = 'Sonoo'
WHERE Student_Id = '3'
Output:
Output:
o If you want to save all the commands which are executed in a transaction,
then just after completing the transaction, you have to execute
the commit command. This command will save all the commands which
are executed on a table. All these changes made to the table will be saved
to the disk permanently.
Example:
SQL1;SET autocommit=0;
INSERT INTO emp VALUES(12, 'rani',
'2023-05-05'); COMMIT;
Output:
2. ROLLBACK
Example:
SQL1;SET autocommit=0;
0;START TRANSACTION;INSERT INTO emp VALUES(12, 'rani', '2023-05-05');
delete from emp where name='rani';
Output:
SELECT * FROM
sql_work.emp; Rollback;
Output:
Page No:
3. SAVEPOINT:
Syntax:
SAVEPOINT savepoint_name;
After setting a savepoint, you can later use the ROLLBACK TO statement to
roll back to that specific savepoint within the transaction.
ROLLBACK TO savepoint_name;
Example:
use sql_work;
SET autocommit=0;
INSERT INTO emp VALUES (12, 'rani', '2023-05-05');
savepoint A;
COMMIT;
delete from emp where name='rani';
Rollback to A;
Rollback;
commit;
Output: