Commands:: A Complete Guide
Commands:: A Complete Guide
Commands:: A Complete Guide
Commands:
A Complete Guide
02 codebasics.io
Provide the
name of the
person whose Dhaval
roll number
is 15.
SQL Commands
03 codebasics.io
Truncate Delete
1 DDL COMMANDS:
DDL stands for Data Definition Language.
DDL Commands are used to define, modify, and delete the structure of
database objects like tables, indexes, views, and schemas.
CREATE:
This command is used to create new objects in the database.
Syntax:
CREATE TABLE table_name (column1 datatype, column2 datatype, ...);
04 codebasics.io
ALTER:
This command is used to alter the structure of the database.
Syntax:
ALTER TABLE table_name
ADD column_name datatype(size);
Syntax:
ALTER TABLE table_name
MODIFY column_name datatype(size);
Syntax:
ALTER TABLE table_name
DROP COLUMN column_name;
Syntax:
ALTER TABLE table_name
RENAME COLUMN old_column_name TO new_column_name;
TRUNCATE:
Removes all records from a table without deleting the table structure.
Syntax:
TRUNCATE TABLE table_name;
DROP:
Deletes an entire table and its data.
Syntax:
DROP TABLE table_name;
05 codebasics.io
2 DML COMMANDS:
DML stands for Data Manipulation Language.
INSERT:
Inserts new data into a table.
Syntax:
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
SELECT:
Retrieves data from one or more tables.
Syntax:
SELECT column1, column2 FROM table_name;
06 codebasics.io
UPDATE:
Modifies existing data in a table.
Syntax:
UPDATE table_name SET column1 = value1 WHERE condition;
DELETE:
Removes data from a table based on a condition.
Syntax:
DELETE FROM table_name WHERE condition;
3 DCL COMMANDS:
DCL stands for Data Control Language.
DCL Commands are used to grant and revoke user access to database
resources.
GRANT REVOKE
07 codebasics.io
GRANT:
It is used to give user access privileges to a database.
Syntax:
GRANT <privilege_name> [ON <object_name>] TO <grantee> [WITH
GRANT OPTION];
REVOKE:
It is used to give take-back access privileges from the user.
Syntax:
REVOKE <privilege_name> [ON <object_name>] FROM <grantee>
[CASCADE | RESTRICT];
4 TCL COMMANDS:
TCL stands for Transaction Control Language.
Final
Output
COMMIT ROLLBACK
08 codebasics.io
COMMIT:
It is used to save all changes made during the current transaction.
Syntax: COMMIT;
ROLLBACK:
It is used to revert changes made during the current transaction.
Syntax: ROLLBACK;
ROLLBACK
ROLLBACK
SAVEPOINT
SAVAPOINT:
It is used to save the different parts of the same transaction using different names.
codebasics.io