DDL DML DCL TCL and DQL - Index
DDL DML DCL TCL and DQL - Index
SQL Commands
SQL commands are instructions. It is used to communicate with the database.
It is also used to perform specific tasks, functions, and queries of data.
SQL can perform various tasks like create a table, add data to tables, drop the
table, modify the table, set permission for users.
o All the command of DDL are auto-committed that means it permanently save
all the changes in the database.
o ALTER
o DROP
o TRUNCATE
Syntax:
Example:
b. DROP: It is used to delete both the structure and record stored in the table.
Example
c. 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:
TRUNCATE: It is used to delete all the rows from the table and free the space
containing the table.
Syntax:
Example:
o INSERT
o UPDATE
o DELETE
a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the
row of a table.
Syntax:
b. UPDATE: This command is used to update or modify the value of a column in the
table.
Syntax:
[WHERE CONDITION]
Syntax:
Ex:
CREATE LOGIN test WITH PASSWORD ='6646'
o Grant
o Revoke
Example
ALTER Ability to perform ALTER TABLE statements to change the table definition.
BEGIN TRY
BEGIN TRANSACTION
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
END CATCH
a. Commit: Commit command is used to save all the transactions to the database.
Syntax:
COMMIT;
Example:
b. Rollback: Rollback command is used to undo transactions that have not already
been saved to the database.
Syntax:
ROLLBACK;
Example:
BEGIN TRANSACTION
-- this will commit the transaction leaving just the first INSERT
COMMIT
SELECT
SELECT: This is the same as the projection operation of relational algebra. It is used
to select the attribute based on the condition described by WHERE clause.
Indexes are used to retrieve data from the database more quickly than otherwise.
The users cannot see the indexes, they are just used to speed up searches/queries.
Index Follow B Tree Structure