Problem Solving_Programs
Problem Solving_Programs
• SQL can perform various tasss lise create a tables add data to tabless dropthe
tables modify the tables set permission for users.
• All the command of DDL are auto-committed that means it permanently saveall
the changes in the database.
• CREATE
• ALTER
• DROP
• TRUNCATE
Syntax:
COLUMN_NAME1 DATATYPES(size)sCOLUMN_NAME2
DATATYPES(size)s
COLUMN_NAMEN DATATYPES(size)s
);
Example: CREATE
TABLE EMP(
EMPNo VARCHAR2(20)s
EName VARCHAR2(20)s
DATE
);
• DROP : This statement is used to drop an existing database. When you use this
statement, complete information present in the database will be lost.
Syntax
DROP DATABASE DatabaseName;
Example
DROP DATABASE Employee;
The ‘DROP TABLE’ Statement
This statement is used to drop an existing table. When you use this statement,
complete information present in the table will be lost.
Syntax
DROP TABLE TableName;
Example
DROP Table Emp;
• ALTER
This command is used to delete, modify or add constraints or columns in an
existingtable.
The ‘ALTER TABLE’ Statement
This statement is used to add, delete, modify columns in an existing table.
The ‘ALTER TABLE’ Statement with ADD/DROP COLUMN
You can use the ALTER TABLE statement with ADD/DROP Column command
according to your need. If you wish to add a column,
then you will use the ADD command, and if you wish to delete a column, then you will
use the DROP COLUMN command.
Syntax
• ALTER TABLE TableName ADD ColumnName Datatype;
Syntax:
Example:
• INSERT
• UPDATE
• DELETE
Syntax:
Or
For example:
Syntax:
For example:
Syntax1:
Syntax1
Example2: Delete all rows from emp table whose Ename is SCOTT
• Grant
• Revose
Example
Example
• COMMIT
• ROLLBACK
• SAVEPOINT
• Commit: Commit command is used to save all the transactions to the
database.
Syntax:
COMMIT;
Example:
COMMIT;
Syntax:
ROLLBACK;
Example:
ROLLBACK;
Syntax:
SAVEPOINT SAVEPOINT_NAME;
SELECT
This statement is used to select data from a database and the data returned is stored
ina result table, called the result-set.
Syntax
Apart from just using the SELECT keyword individually, you can use the
followingkeywords with the SELECT statement:
DISTINCT CLAUSE
-------------------------
The ‘SELECT DISTINCT’ Statement
This statement is used to return only different values.
Syntax
Example