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 creating a table. add data to tables, drop the table modify the table. set permission for users.
Types of SQL Commands: There are five types of SQL Commands:
Data Definition Language (DDL)
- DDL changes the table’s structure like creating a table deleting a table, altering a table, etc.
- All the commands of DDL are auto-committed. That means it permanently saves all the changes in the database
- Here are some commands that come under DDL:
It is used to create a new table in the database Syntax:
CREATE TABLE_NAME CCOLUMN_NAME DATATYPE)
CREATE TABLE EMPLOYEE (Name VARCHAR2(20), Email V
It is used to delete both the structure and record stored in the table
DROP TABLE table_name;
DROP TABLE EMPLOYEE;
It is used to alter the structure of the database. This could be either to modify the characteristics of an existing attribute or probably to add a new attribute.
ALTER TABLE STU-DETAILS ADD CADDRESS 'VARCHAR 2 (20 ALTER TABLE STU-DETAILS MODIFY (NAME VARCHAR 2 (20));
It is used to delete all the rows from the table and free the space containing the table
TRUNCATE TABLE table-name
TRUNCATE TABLE Employee
Data Manipulation Language
DML commands are used to modify the database. It is responsible for all the form of changes in the database. The command of DML is not auto committed.
The Insert Statement is SQL Query. It is used to insert data into a row of tables.
INSERT INTO TABLE_NAME VALUES(VAL1,VAL2,VAL3,VAL4..)
This command is used to update or modify the value of a column in the table.
UPDATE Table_name set[col1=val1, col2=val2..]
It is used to remove one or more rows from a table
DELETE FROM GEEKYCODES WHERE AUTHOR="XAVIER"
3. Data Control Language
DCL Commands are used to grant and revoke authority from any database user
It is used to give user access privileges to the database.
GRANT SELECT,UPDATE ON MY_TABLE TO SOME_USER,A
It is used to take back permissions from the user
Transaction Control Language
TCL Commands can only be used with DML commands like INSERT,DELETE and UPDATE only
Commit is used to save all the transactions to the database.
DELETE FROM CUSTOMERS WHERE AGE=25 COMMIT
Roll back command is used to undo transactions that have not already been saved to the database.
c.) SAVE POINT:
It is used to roll the transaction back to a certain. point without rolling back the entire transaction.
SAVE POINT SAVEPOINT-NAME
DATA QUERY LANGUAGE!
a. SELECT: This is the same as the projection operation of relational algebra. It is used to select the attribute based on the competition.
SELECT expressions FROM TABLES WHERE conditions:
Important Notice for college students
If you’re a college student and have skills in programming languages, Want to earn through blogging? Mail us at firstname.lastname@example.org