13. ALTER USER Command
We generally we use the ALTER USER Command to create users in the database and once the users are created we need to do some changes, such as Password Change, which is one of the common changes we do and for this we use the ALTER USER Command.
Syntax
ALTER USER Username IDENTIFIED BY New_Password;
Example
ALTER USER Joseph IDENTIFIED BY JJJPh;
14. ALTER TRIGGER Command
In response to the specific event a trigger fires as a code block. ALTER TRIGGER changes the property of a trigger.
Syntax
ALTER TRIGGER trigger_name COMPILE;
ALTER TRIGGER trigger_name ENABLE;
ALTER TRIGGER trigger_name DISABLE;
Example
To Alter a Trigger first we create a table "STUDENTS" and then create a trigger as in the following:
Table
CREATE TABLE Product
(
Prod_ID Number(10),
Prod_Name Varchar2(20),
Quantity Number(5),
Price number(5,2),
Create_date date,
Created_by varchar2(10)
);
STUDENTS
| Stu_ID | Stu_Name | RollNo | Stream |
| 101 | Shreya | 5 | Commerce |
| 102 | Rohan | 9 | Science |
| 103 | Ronit | 17 | Science |
Trigger
CREATE OR REPLACE TRIGGER Product_before_insert
BEFORE INSERT
ON Products
FOR EACH ROW
DECLARE
username varchar2(15);
BEGIN
-- Find username of person performing INSERT into table
SELECT user INTO username
FROM dual;
-- Update create_date field to current system date
:new.create_date := systemdate;
-- Update created_by field to the username of the person performing the INSERT
:new.created_by := username;
END;
Now, Alter the trigger Product_before_insert as in the following:
ALTER TRIGGER Product_before_insert DISABLE;
15. ALTER SEQUENCE Command
To change the behavior of an existing sequence the ALTER SEQUENCE COMMAND is used. It will alter the values of an existing Oracle sequence.
Syntax
ALTER SEQUENCE seq_name
increment by Value(i);
Example
ALTER USER Username IDENTIFIED BY New_Password;
ALTER SEQUENCE Master
Increment by 124
SELECT Master.nextval from dual;
ALTER SEQUENCE master
IMZCREMENT BY 1;
16. ALTER SESSION Command
ALTER SESSION Command is used to modify any parameter or condition that can affect the connection to our database. Also it is used when the database has multiple schema owners.
Syntax and Example
- To change the Schema
To add "SYSADM" to all your SQL statements, change the current schema setting to "SYSADM":
ALTERSESSION SETCURRENT_SCHEMA =SYSADM;
- To change NLS_DATE_FORMAT
To set the date format instead of using the "TO_DATE" function in every SQL statement:ALTERSESSION SETNLS_DATE_FORMAT ='YYYY-MM-DD';
17. DROP TABLE Command
To remove the objects from the database we use the DROP Command. Here we are talking about the DROP TABLE Command, while dropping a table all the rows, indexes and privileges will also be removed. It may also be used to remove a database link.
Syntax
DROP TABLE "table_Name";
Example
Suppose we want to drop the following table created as in the following:
CREATE TABLE Student
(
Stu_ID Number(10),
Stu_Name varchar2(20),
RollNo Number(10),
Stream varchar2(20)
);
STUDENTS
| Stu_ID | Stu_Name | RollNo | Stream |
| 101 | Shreya | 5 | Commerce |
| 102 | Rohan | 9 | Science |
| 103 | Ronit | 17 | Science |
DROP TABLE "Student";
18. DROP VIEW Command
If a view exists in in the database and we want to drop it, then a DROP VIEW command allows the user to select a view and drop it.
Syntax
DROP VIEW [IF EXISTS]
view_name [, view_name] ...
[RESTRICT | CASCADE]
OR
DROP VIEW [schema.]view [CASCADE CONSTRAINTS]
Example
Suppose we want to drop the View created for the following table.
EMPLOYEE TABLE

Join the conversation! Your thoughts help the community grow.