SlideShare a Scribd company logo
Understand basic concepts of SQL*Plus overview and Oracle
views
Managing constraints
1. What Does "Creating Constraints" Mean?
Creating constraints means defining rules at the time of table creation or later using SQL
commands. These rules restrict the kind of data that can be inserted into the table to
protect the quality of data.
Common Types of Constraints:
2. Adding Constraints:
A. At Table Creation:
CREATE TABLE employees (emp_id INT PRIMARY KEY, name VARCHAR(50) NOT NULL, salary
INT CHECK (salary > 0), dept_id INT, FOREIGN KEY (dept_id) REFERENCES
departments(dept_id));
B. After Table Creation (Using ALTER):
ALTER TABLE employees ADD CONSTRAINT fk_dept FOREIGN KEY (dept_id) REFERENCES
departments(dept_id);
Understand basic concepts of SQL*Plus overview and Oracle
views
Managing constraints
2. Dropping Constraints:
You can remove a constraint using its name:
ALTER TABLE employees DROP CONSTRAINT fk_dept;
Note: In MySQL, you may need to use DROP FOREIGN KEY instead of DROP CONSTRAINT.
3. Enabling/Disabling Constraints:
These options are mostly available in Oracle and some other RDBMS:
Disable a constraint:
ALTER TABLE employees DISABLE CONSTRAINT fk_dept;
Enable it again:
ALTER TABLE employees ENABLE CONSTRAINT fk_dept;
4. Renaming Constraints:
Some systems allow renaming constraints:
ALTER TABLE employees RENAME CONSTRAINT old_name TO new_name;
Understand basic concepts of SQL*Plus overview and Oracle
views
Managing constraints
Deferring constraint check
In Database Management Systems (DBMS), particularly in relational databases like Oracle, deferring constraint
checks refers to postponing the enforcement of certain constraints (like foreign key constraints) until the end of
a transaction, rather than checking them immediately after each DML (Data Manipulation Language) operation
(INSERT, UPDATE, DELETE).
Key Concepts:
1. Constraints:
Constraints are rules enforced on data in a table. Common types include:
• PRIMARY KEY
• FOREIGN KEY
• UNIQUE
• NOT NULL
• CHECK
By default, most constraints are checked immediately after a DML statement.
2. Immediate vs Deferred Constraints:
• Immediate Constraint: Checked right after the DML operation.
• Deferred Constraint: Checked only at the end of the transaction, during COMMIT.
Understand basic concepts of SQL*Plus overview and Oracle
views
Managing constraints
Deferring constraint check
How to Defer Constraints (Oracle Example):
1. Declare a Constraint as Deferrable
CREATE TABLE employee (emp_id NUMBER PRIMARY KEY, mgr_id NUMBER, CONSTRAINT fk_mgr
FOREIGN KEY (mgr_id) REFERENCES employee(emp_id) DEFERRABLE INITIALLY IMMEDIATE);
2. Defer it at Runtime
SET CONSTRAINTS fk_mgr DEFERRED;
3. Defer All Constraints
SET CONSTRAINTS ALL DEFERRED;
4. Transaction-Level Defer
BEGIN;
SET CONSTRAINTS ALL DEFERRED;
--- DML operations here
COMMIT;
Understand basic concepts of SQL*Plus overview and Oracle
views
Managing views
Managing views in a DBMS (Database Management System) is an essential part of database administration,
as views help provide security, simplicity, and abstraction over complex queries and data.
What is a View?
A view is a virtual table based on the result of a SELECT query. It does not store data itself but displays data
from one or more base tables.
CREATE VIEW view_name ASSELECT column1, column2 FROM table_name WHERE condition;
Managing Views as a DBA
1. Creating Views
CREATE VIEW emp_view AS SELECT emp_id, emp_name, salary FROM employee WHERE dept = 'Sales';
2. Viewing Existing Views
SELECT view_name FROM user_views;
3. Modifying a View
You can’t use ALTER VIEW to change the SELECT logic. Instead:
CREATE OR REPLACE VIEW emp_view AS SELECT emp_id, emp_name FROM employee WHERE dept = 'HR';
4. Dropping a View
DROP VIEW emp_view;
Understand basic concepts of SQL*Plus overview and Oracle
views
Managing views
5. Updating a View
You can’t directly update a view using ALTER VIEW in most DBMS when you want to change
the query logic. Instead, you replace the existing view using:
1. CREATE OR REPLACE VIEW
This is the standard way to update a view’s definition.
Syntax
CREATE OR REPLACE VIEW view_name AS SELECT columns FROM table_name WHERE
condition;
If the view exists, it will be replaced. If the view does not exist, it will be created.
Example
--- Original view
CREATE VIEW emp_view ASSELECT emp_id, emp_name FROM employee;
-- Updated view (adds salary column)
CREATE OR REPLACE VIEW emp_view AS SELECT emp_id, emp_name, salary FROM employee;
Understand basic concepts of SQL*Plus overview and Oracle
views
Managing views
6. Inserting into a View
Inserting into a view means using the INSERT statement on a view instead of directly on a base table.
This is only possible if the view is updatable.
Syntax
INSERT INTO view_name (column1, column2, ...)
VALUES (value1, value2, ...);
Example
Base Table
CREATE TABLE employee (emp_id INT PRIMARY KEY, emp_name VARCHAR(50), salary NUMBER, dept
VARCHAR(30));
View
CREATE VIEW emp_view AS SELECT emp_id, emp_name, salary FROM employee;
Insert Through View
INSERT INTO emp_view (emp_id, emp_name, salary)VALUES (105, 'Sara', 5000);
This will insert into the employee table via the view.

More Related Content

PPTX
Oracle views
PPT
Sql views
PPT
Creating Views - oracle database
PPT
Les12[1]Creating Views
PPTX
DBMS week 2 hjghg hvgfhgf,3 BSCS 6th.pptx
PPT
database management system lessonchapter
Oracle views
Sql views
Creating Views - oracle database
Les12[1]Creating Views
DBMS week 2 hjghg hvgfhgf,3 BSCS 6th.pptx
database management system lessonchapter

Similar to DBMS weSDFDDDFDFDFDSSek 4,5 BSCS 6th.pptx (20)

PPT
PPT
Less07 schema
PDF
Database Oracle Basic
PPT
Structure query language - Data definition language.ppt
PPT
PPTX
Unit 2 Chap 4 SQL DDL.pptx
PPT
Using ddl statements to create and manage tables
PPTX
DDL(Data defination Language ) Using Oracle
PPTX
PPT
Oracle training institute in hyderabad
PPT
PPT
SQL WORKSHOP::Lecture 12
PPT
Les09[1]Manipulating Data
PDF
SQL & Adv SQL - Basics and Advanced for Beginners
PDF
Lesson10
PPT
Creating other schema objects
PPT
Module 3 _SQL Database Management System
PDF
SQL-8 Table Creation.pdf
PPT
Oracle view
Less07 schema
Database Oracle Basic
Structure query language - Data definition language.ppt
Unit 2 Chap 4 SQL DDL.pptx
Using ddl statements to create and manage tables
DDL(Data defination Language ) Using Oracle
Oracle training institute in hyderabad
SQL WORKSHOP::Lecture 12
Les09[1]Manipulating Data
SQL & Adv SQL - Basics and Advanced for Beginners
Lesson10
Creating other schema objects
Module 3 _SQL Database Management System
SQL-8 Table Creation.pdf
Oracle view
Ad

Recently uploaded (20)

PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
From loneliness to social connection charting
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Onica Farming 24rsclub profitable farm business
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
O5-L3 Freight Transport Ops (International) V1.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
Revamp in MTO Odoo 18 Inventory - Odoo Slides
Open Quiz Monsoon Mind Game Prelims.pptx
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
From loneliness to social connection charting
Module 3: Health Systems Tutorial Slides S2 2025
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Onica Farming 24rsclub profitable farm business
Ad

DBMS weSDFDDDFDFDFDSSek 4,5 BSCS 6th.pptx

  • 1. Understand basic concepts of SQL*Plus overview and Oracle views Managing constraints 1. What Does "Creating Constraints" Mean? Creating constraints means defining rules at the time of table creation or later using SQL commands. These rules restrict the kind of data that can be inserted into the table to protect the quality of data. Common Types of Constraints: 2. Adding Constraints: A. At Table Creation: CREATE TABLE employees (emp_id INT PRIMARY KEY, name VARCHAR(50) NOT NULL, salary INT CHECK (salary > 0), dept_id INT, FOREIGN KEY (dept_id) REFERENCES departments(dept_id)); B. After Table Creation (Using ALTER): ALTER TABLE employees ADD CONSTRAINT fk_dept FOREIGN KEY (dept_id) REFERENCES departments(dept_id);
  • 2. Understand basic concepts of SQL*Plus overview and Oracle views Managing constraints 2. Dropping Constraints: You can remove a constraint using its name: ALTER TABLE employees DROP CONSTRAINT fk_dept; Note: In MySQL, you may need to use DROP FOREIGN KEY instead of DROP CONSTRAINT. 3. Enabling/Disabling Constraints: These options are mostly available in Oracle and some other RDBMS: Disable a constraint: ALTER TABLE employees DISABLE CONSTRAINT fk_dept; Enable it again: ALTER TABLE employees ENABLE CONSTRAINT fk_dept; 4. Renaming Constraints: Some systems allow renaming constraints: ALTER TABLE employees RENAME CONSTRAINT old_name TO new_name;
  • 3. Understand basic concepts of SQL*Plus overview and Oracle views Managing constraints Deferring constraint check In Database Management Systems (DBMS), particularly in relational databases like Oracle, deferring constraint checks refers to postponing the enforcement of certain constraints (like foreign key constraints) until the end of a transaction, rather than checking them immediately after each DML (Data Manipulation Language) operation (INSERT, UPDATE, DELETE). Key Concepts: 1. Constraints: Constraints are rules enforced on data in a table. Common types include: • PRIMARY KEY • FOREIGN KEY • UNIQUE • NOT NULL • CHECK By default, most constraints are checked immediately after a DML statement. 2. Immediate vs Deferred Constraints: • Immediate Constraint: Checked right after the DML operation. • Deferred Constraint: Checked only at the end of the transaction, during COMMIT.
  • 4. Understand basic concepts of SQL*Plus overview and Oracle views Managing constraints Deferring constraint check How to Defer Constraints (Oracle Example): 1. Declare a Constraint as Deferrable CREATE TABLE employee (emp_id NUMBER PRIMARY KEY, mgr_id NUMBER, CONSTRAINT fk_mgr FOREIGN KEY (mgr_id) REFERENCES employee(emp_id) DEFERRABLE INITIALLY IMMEDIATE); 2. Defer it at Runtime SET CONSTRAINTS fk_mgr DEFERRED; 3. Defer All Constraints SET CONSTRAINTS ALL DEFERRED; 4. Transaction-Level Defer BEGIN; SET CONSTRAINTS ALL DEFERRED; --- DML operations here COMMIT;
  • 5. Understand basic concepts of SQL*Plus overview and Oracle views Managing views Managing views in a DBMS (Database Management System) is an essential part of database administration, as views help provide security, simplicity, and abstraction over complex queries and data. What is a View? A view is a virtual table based on the result of a SELECT query. It does not store data itself but displays data from one or more base tables. CREATE VIEW view_name ASSELECT column1, column2 FROM table_name WHERE condition; Managing Views as a DBA 1. Creating Views CREATE VIEW emp_view AS SELECT emp_id, emp_name, salary FROM employee WHERE dept = 'Sales'; 2. Viewing Existing Views SELECT view_name FROM user_views; 3. Modifying a View You can’t use ALTER VIEW to change the SELECT logic. Instead: CREATE OR REPLACE VIEW emp_view AS SELECT emp_id, emp_name FROM employee WHERE dept = 'HR'; 4. Dropping a View DROP VIEW emp_view;
  • 6. Understand basic concepts of SQL*Plus overview and Oracle views Managing views 5. Updating a View You can’t directly update a view using ALTER VIEW in most DBMS when you want to change the query logic. Instead, you replace the existing view using: 1. CREATE OR REPLACE VIEW This is the standard way to update a view’s definition. Syntax CREATE OR REPLACE VIEW view_name AS SELECT columns FROM table_name WHERE condition; If the view exists, it will be replaced. If the view does not exist, it will be created. Example --- Original view CREATE VIEW emp_view ASSELECT emp_id, emp_name FROM employee; -- Updated view (adds salary column) CREATE OR REPLACE VIEW emp_view AS SELECT emp_id, emp_name, salary FROM employee;
  • 7. Understand basic concepts of SQL*Plus overview and Oracle views Managing views 6. Inserting into a View Inserting into a view means using the INSERT statement on a view instead of directly on a base table. This is only possible if the view is updatable. Syntax INSERT INTO view_name (column1, column2, ...) VALUES (value1, value2, ...); Example Base Table CREATE TABLE employee (emp_id INT PRIMARY KEY, emp_name VARCHAR(50), salary NUMBER, dept VARCHAR(30)); View CREATE VIEW emp_view AS SELECT emp_id, emp_name, salary FROM employee; Insert Through View INSERT INTO emp_view (emp_id, emp_name, salary)VALUES (105, 'Sara', 5000); This will insert into the employee table via the view.