SQL Fundamentals, DDL, DML, DCL
SQL Fundamentals, DDL, DML, DCL
Syntax:
CREATE TABLE TABLE_NAME (COLUMN 1_NAME DATATYPES, COLUMN
2_NAME DATATYPES[,.........]);
Example:
CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Employee id INT, Email
VARCHA R2(100), DOB DATE);
Data Definition Language (DDL)- Drop,
RENAME
Drop: It is used to delete both the structure and record stored
in the table.
Syntax:
DROP TABLE table_name;
Example:
DROP TABLE EMPLOYEE;
Example:
RENAME EMP TO EMP2;
Data Definition Language (DDL)- ALTER
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:
ALTER TABLE table_name ADD column_name COLUMN-definition;
ALTER TABLE MODIFY(COLUMN DEFINITION....);
Example:
ALTER TABLE STU_DETAILS ADD(ADDRESS VARCHAR2(20));
ALTER TABLE STU_DETAILS MODIFY (NAME VARCHAR2(20));
Data Definition Language (DDL)- TRUNCATE
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;
Data Manipulation Language
• DML commands are used to modify the database. It is
responsible for all form of CHANGES in the database.
OR
INSERT INTO TABLE_NAME VALUES (value1, value2, value3, ....
valueN);
Example:
INSERT INTO Customers (customer_id, first_name,
last_name, age, country) VALUES (6, 'Alice', 'Brown', 30,
'Canada');
Data Manipulation Language - UPDATE
Update: This command is used to update or modify the value of a
column in the table.
Syntax:
UPDATE table_name SET [column_name1= value1,...column_n
ameN = valueN] [WHERE CONDITION]
Example:
UPDATE Customers
SET age = 29
WHERE customer_id = 5;
Data Manipulation Language - DELETE
DELETE
The SQL DELETE statement is used to delete row(s) from a
database table.
Syntax:
DELETE FROM table-name
For example,
DELETE FROM Customers
WHERE country = 'UAE';
Data Control Language
DCL commands are used to GRANT and TAKE BACK
authority from any database user.
Revoke
Data Control Language (DCL)
DCL commands include GRANT and REVOKE, which are used to control access
to the database.
i. GRANT
In SQL, the GRANT statement gives users access privileges to the database.
For example,
GRANT SELECT, UPDATE ON Customers TO user1;
This command grants SELECT and UPDATE permissions on
the Customers table to user1.
ii. REVOKE
In SQL, the REVOKE statement withdraws access privileges given by
the GRANT statement.
Let's look at an
example.
REVOKE SELECT ON Customers FROM user1;
Here, the SQL query revokes SELECT permission on the Customers table
from user1.
Data Control Language - Grant
GRANT: It is used to give user access privileges (permissions) to a
database.
Example:
Example:
= It checks if two operands values are equal or not, if the values are
queal then condition becomes true.
!= It checks if two operands values are equal or not, if values are not
equal, then condition becomes true.
<> It checks if two operands values are equal or not, if values are not
equal then condition becomes true.
<= It checks if the left operand value is less than or equal to the right
operand value, if yes then condition becomes true.
!< It checks if the left operand value is not less than the right operand
value, if yes then condition becomes true.
!> It checks if the left operand value is not greater than the right operand
value, if yes then condition becomes true.
SQL Logical Operators
Operator Description
All It compares a value to all values in another value set.
Between It is used to search for values that are within a set of values.
4. Web Development
5. Data Warehousing