SlideShare a Scribd company logo
1 of 21
Download to read offline
SQL Fundamentals
Oracle 11g
M U H A M M A D WA H E E D
O R A C L E D ATA B A S E D E VE L O P E R
E M A I L : m.w a h e e d 3 6 6 8 @ g ma i l . c om
.
1
Lecture#3
Lab Work Video Tutorial
•Video is embedded inside the slides.
•Go through each slide for conceptual knowledge then practical is
performed in the video that is provided in last slides.
2
COMMENTS
•Use the COMMENT statementto add to the data dictionary a comment
about a table or table column etc.
•We use following syntax for creating comments:
COMMENT ON TABLE <table_name> IS ‘<comment_statement>’;
or
COMMENT ON COLUMN <table_name>.<column_name>
IS ‘<comment_statement>';
•We use following syntax to remove/drop comments:
COMMENT ON TABLE <table_name> IS ' ';
or
COMMENT ON COLUMN <table_name>.<column_name>IS ' ';
3
View COMMENTS
•SELECT * FROM USER_COL_COMMENTS;
•SELECT * FROM USER_TAB_COMMENTS;
4
Data Types
Data Type Description
VARCHAR2( size ) Variable length character data with
specified size ( 1 to 4000)
INT Fixed length number data type with default
size 38.
CHAR [ size ] Fixed length character data of specified size
( 1 to 2000)
NUMBER [ p,s ] Number having precision p(1 to 38) and
scale s(-84 to 127)
Date It must be between January 1, 4712 and
December 31,9999
TIMESTAMP(s) It is date+time data type with scale
specified from user on the right of decimal
point in time. Scale is 6 by default.
5
Data Integrity Constraints
•These are used to enforce limitations on the data entered in tables.
•It have two levels:
column level(applied on specific column definition)
table level(applied at table definition)
6
Column Level Constraints
•Column level constraints are defined with following syntax:
CREATE TABLE <table_name>
(<column_name> <data_type> <constraint_definition>);
7
Table Level Constraints
•Table level constraints are defined with following syntanx:
CREATE TABLE <table_name>
(<column_name> <data_type>,
<column_name> <data_type>,
CONSTRAINT<constraint_name> <constraint_definition>);
8
Constraint Types
•There are following five constraints:
1- NULL/NOT NULL
2- UNIQUE
3- PRIMARYKEY
4- FOREIGN KEY
5- CHECK
9
NULL/NOT NULL Constraint
•It determines whether a column can be blank or not.
•It is only possible at column level.
•By default each column is set to NULL.
•Example (column level):
CREATE TABLE student
( std_id NUMBER(4) NOT NULL,
std_name VARCHAR2(30));
•Example(table level):
ALTER TABLE student
MODIFY std_name VARCHAR2(30)NOT NULL);
10
UNIQUE Constraint
•It is used for a field which needs to be unique but also can be
null/empty.
•Example (column level):
contact_no of student table can be empty but must be unique.
CREATE TABLE student
( std_contact_no NUMBER(4)CONSTRAINTcontact_uk UNIQUE,
);
• Example(table level):
CREATE TABLE student
(std_contact_no int,
CONSTRAINTcontact_uk UNIQUE(std_contact_no));
11
PRIMARY KEY Constraint
•It restricts the duplication of values and doesn’t allow null values.
•Example(columnlevel):
CREATE TABLE student
( std_id int PRIMARYKEY,
std_name varchar2(100));
•Example( table level):
CREATE TABLE student
(std_id int,
CONSTRAINTstdid_pk PRIMARY KEY(std_id));
12
FOREIGN KEY Constraint
•It is used to create the link between data of two tables.
•It is based on common field in two tables where parent table have
primary key and child table uses it as foreign key.
•One table can have multiple foreign keys.
•Example(columnlevel):
CREATE TABLE result
( std_id int REFERENCES student);
•Example(table level):
CREATE TABLE result
(std_id int,
CONSTRAINTstdid_fk FOREIGN KEY(std_id)REFERENCES
student(std_id));
13
CHECK Constraint
•Defines a condition that each row mustsatisfy.
•It is only possible at column level.
•Example(columnlevel):
CREATE TABLE student
( age int CONSTRAINTstd_age CHECK(age>18));
•Example(table level):
CREATE TABLE result
(age int,
CONSTRAINTstd_age CHECK (age>18));
14
Modify Constraints
•SQL provides the facility of modification of constraints on existing
schemas.
•There are four following facilities to be used on constraints :
Add
Drop
Enable
Disable
Cascade
15
ADD Constraint
•ADD constraint:
ALTER TABLE <table_name>
ADD CONSTRAINT<constraint_name><constraint_defination>;
16
DROP Constraint
•DROPconstraint:
ALTER TABLE <table_name>
DROPCONSTRAINT<constraint_name>;
•*Note: PRIMARYKEY as a special case uses “CASCADE” to disable its
foreign keys. For example:
ALTER TABLE student
DROPPRIMARYKEY CASCADE;
In above case foreign key constraint on result table will be deleted too.
17
DISABLE Constraint
•DROPconstraint:
ALTER TABLE <table_name>
DISABLECONSTRAINT<constraint_name>CASCADE;
•Apply the “CASCADE” option to disable its dependent integrity
constraints.
18
ENABLE Constraint
•It is used to ENABLE the DISABLED constraints:
ALTER TABLE <table_name>
ENABLE CONSTRAINT<constraint_name>;
19
CASCADE Constraint
•The CASCADE constraints clause is used along with the DROPCOLUMN
clause.
•The CASCADE clause drops all referential integrity constraints that refer
to the primary and unique keys defined on the dropped columns.
•The CASCADE clause also drops all multicolumn constraints defined on
the dropped columns.
•Example:
ALTER TABLE <table_name>
DROP(<constraint_name(s)>)CASCADECONSTRAINTS;
20
Your Suggestions/Feedback?
-Elbert Hubbard
21
Email: m.waheed3668@gmail.com

More Related Content

What's hot

SQL Functions - Oracle SQL Fundamentals
SQL Functions - Oracle SQL FundamentalsSQL Functions - Oracle SQL Fundamentals
SQL Functions - Oracle SQL FundamentalsMuhammadWaheed44
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statementsMohd Tousif
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESVENNILAV6
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteAl-Mamun Sarkar
 
SQL: Structured Query Language
SQL: Structured Query LanguageSQL: Structured Query Language
SQL: Structured Query LanguageRohit Bisht
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL CommandsShrija Madhu
 
Sql delete, truncate, drop statements
Sql delete, truncate, drop statementsSql delete, truncate, drop statements
Sql delete, truncate, drop statementsVivek Singh
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commandsBelle Wx
 
SQL-Alter Table, SELECT DISTINCT & WHERE
SQL-Alter Table, SELECT DISTINCT & WHERESQL-Alter Table, SELECT DISTINCT & WHERE
SQL-Alter Table, SELECT DISTINCT & WHEREI L0V3 CODING DR
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands1keydata
 

What's hot (19)

SQL Functions - Oracle SQL Fundamentals
SQL Functions - Oracle SQL FundamentalsSQL Functions - Oracle SQL Fundamentals
SQL Functions - Oracle SQL Fundamentals
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
Sql commands
Sql commandsSql commands
Sql commands
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and delete
 
SQL: Structured Query Language
SQL: Structured Query LanguageSQL: Structured Query Language
SQL: Structured Query Language
 
DML Commands
DML CommandsDML Commands
DML Commands
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
Sql delete, truncate, drop statements
Sql delete, truncate, drop statementsSql delete, truncate, drop statements
Sql delete, truncate, drop statements
 
Sql commands
Sql commandsSql commands
Sql commands
 
1 ddl
1 ddl1 ddl
1 ddl
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
SQL-Alter Table, SELECT DISTINCT & WHERE
SQL-Alter Table, SELECT DISTINCT & WHERESQL-Alter Table, SELECT DISTINCT & WHERE
SQL-Alter Table, SELECT DISTINCT & WHERE
 
SQL commands
SQL commandsSQL commands
SQL commands
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Sql DML
Sql DMLSql DML
Sql DML
 
Database constraints
Database constraintsDatabase constraints
Database constraints
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 

Similar to Oracle SQL Fundamentals - Lecture 3

Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro projectARVIND SARDAR
 
Constraints constraints of oracle data base management systems
Constraints  constraints of oracle data base management systemsConstraints  constraints of oracle data base management systems
Constraints constraints of oracle data base management systemsSHAKIR325211
 
Clase 13 integridad modificada
Clase 13 integridad   modificadaClase 13 integridad   modificada
Clase 13 integridad modificadaTitiushko Jazz
 
Clase 13 integridad modificada
Clase 13 integridad   modificadaClase 13 integridad   modificada
Clase 13 integridad modificadaTitiushko Jazz
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleFarhan Aslam
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...Alex Zaballa
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...Alex Zaballa
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETEAbrar ali
 
Sql coding-standard-sqlserver
Sql coding-standard-sqlserverSql coding-standard-sqlserver
Sql coding-standard-sqlserverlochaaaa
 
SQL-8 Table Creation.pdf
SQL-8 Table Creation.pdfSQL-8 Table Creation.pdf
SQL-8 Table Creation.pdfHannanKhalid4
 
1.Implementing_Data_Integrity.pdf
1.Implementing_Data_Integrity.pdf1.Implementing_Data_Integrity.pdf
1.Implementing_Data_Integrity.pdfdiaa46
 

Similar to Oracle SQL Fundamentals - Lecture 3 (20)

Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
 
Constraints constraints of oracle data base management systems
Constraints  constraints of oracle data base management systemsConstraints  constraints of oracle data base management systems
Constraints constraints of oracle data base management systems
 
Clase 13 integridad modificada
Clase 13 integridad   modificadaClase 13 integridad   modificada
Clase 13 integridad modificada
 
Clase 13 integridad modificada
Clase 13 integridad   modificadaClase 13 integridad   modificada
Clase 13 integridad modificada
 
UNIT2.ppt
UNIT2.pptUNIT2.ppt
UNIT2.ppt
 
Sql commands
Sql commandsSql commands
Sql commands
 
SQL
SQLSQL
SQL
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
Bn1037 demo oracle sql
Bn1037 demo  oracle sqlBn1037 demo  oracle sql
Bn1037 demo oracle sql
 
2..basic queries.pptx
2..basic queries.pptx2..basic queries.pptx
2..basic queries.pptx
 
Module 3
Module 3Module 3
Module 3
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
Sql coding-standard-sqlserver
Sql coding-standard-sqlserverSql coding-standard-sqlserver
Sql coding-standard-sqlserver
 
SQL-8 Table Creation.pdf
SQL-8 Table Creation.pdfSQL-8 Table Creation.pdf
SQL-8 Table Creation.pdf
 
1.Implementing_Data_Integrity.pdf
1.Implementing_Data_Integrity.pdf1.Implementing_Data_Integrity.pdf
1.Implementing_Data_Integrity.pdf
 

Recently uploaded

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 

Recently uploaded (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 

Oracle SQL Fundamentals - Lecture 3

  • 1. SQL Fundamentals Oracle 11g M U H A M M A D WA H E E D O R A C L E D ATA B A S E D E VE L O P E R E M A I L : m.w a h e e d 3 6 6 8 @ g ma i l . c om . 1 Lecture#3
  • 2. Lab Work Video Tutorial •Video is embedded inside the slides. •Go through each slide for conceptual knowledge then practical is performed in the video that is provided in last slides. 2
  • 3. COMMENTS •Use the COMMENT statementto add to the data dictionary a comment about a table or table column etc. •We use following syntax for creating comments: COMMENT ON TABLE <table_name> IS ‘<comment_statement>’; or COMMENT ON COLUMN <table_name>.<column_name> IS ‘<comment_statement>'; •We use following syntax to remove/drop comments: COMMENT ON TABLE <table_name> IS ' '; or COMMENT ON COLUMN <table_name>.<column_name>IS ' '; 3
  • 4. View COMMENTS •SELECT * FROM USER_COL_COMMENTS; •SELECT * FROM USER_TAB_COMMENTS; 4
  • 5. Data Types Data Type Description VARCHAR2( size ) Variable length character data with specified size ( 1 to 4000) INT Fixed length number data type with default size 38. CHAR [ size ] Fixed length character data of specified size ( 1 to 2000) NUMBER [ p,s ] Number having precision p(1 to 38) and scale s(-84 to 127) Date It must be between January 1, 4712 and December 31,9999 TIMESTAMP(s) It is date+time data type with scale specified from user on the right of decimal point in time. Scale is 6 by default. 5
  • 6. Data Integrity Constraints •These are used to enforce limitations on the data entered in tables. •It have two levels: column level(applied on specific column definition) table level(applied at table definition) 6
  • 7. Column Level Constraints •Column level constraints are defined with following syntax: CREATE TABLE <table_name> (<column_name> <data_type> <constraint_definition>); 7
  • 8. Table Level Constraints •Table level constraints are defined with following syntanx: CREATE TABLE <table_name> (<column_name> <data_type>, <column_name> <data_type>, CONSTRAINT<constraint_name> <constraint_definition>); 8
  • 9. Constraint Types •There are following five constraints: 1- NULL/NOT NULL 2- UNIQUE 3- PRIMARYKEY 4- FOREIGN KEY 5- CHECK 9
  • 10. NULL/NOT NULL Constraint •It determines whether a column can be blank or not. •It is only possible at column level. •By default each column is set to NULL. •Example (column level): CREATE TABLE student ( std_id NUMBER(4) NOT NULL, std_name VARCHAR2(30)); •Example(table level): ALTER TABLE student MODIFY std_name VARCHAR2(30)NOT NULL); 10
  • 11. UNIQUE Constraint •It is used for a field which needs to be unique but also can be null/empty. •Example (column level): contact_no of student table can be empty but must be unique. CREATE TABLE student ( std_contact_no NUMBER(4)CONSTRAINTcontact_uk UNIQUE, ); • Example(table level): CREATE TABLE student (std_contact_no int, CONSTRAINTcontact_uk UNIQUE(std_contact_no)); 11
  • 12. PRIMARY KEY Constraint •It restricts the duplication of values and doesn’t allow null values. •Example(columnlevel): CREATE TABLE student ( std_id int PRIMARYKEY, std_name varchar2(100)); •Example( table level): CREATE TABLE student (std_id int, CONSTRAINTstdid_pk PRIMARY KEY(std_id)); 12
  • 13. FOREIGN KEY Constraint •It is used to create the link between data of two tables. •It is based on common field in two tables where parent table have primary key and child table uses it as foreign key. •One table can have multiple foreign keys. •Example(columnlevel): CREATE TABLE result ( std_id int REFERENCES student); •Example(table level): CREATE TABLE result (std_id int, CONSTRAINTstdid_fk FOREIGN KEY(std_id)REFERENCES student(std_id)); 13
  • 14. CHECK Constraint •Defines a condition that each row mustsatisfy. •It is only possible at column level. •Example(columnlevel): CREATE TABLE student ( age int CONSTRAINTstd_age CHECK(age>18)); •Example(table level): CREATE TABLE result (age int, CONSTRAINTstd_age CHECK (age>18)); 14
  • 15. Modify Constraints •SQL provides the facility of modification of constraints on existing schemas. •There are four following facilities to be used on constraints : Add Drop Enable Disable Cascade 15
  • 16. ADD Constraint •ADD constraint: ALTER TABLE <table_name> ADD CONSTRAINT<constraint_name><constraint_defination>; 16
  • 17. DROP Constraint •DROPconstraint: ALTER TABLE <table_name> DROPCONSTRAINT<constraint_name>; •*Note: PRIMARYKEY as a special case uses “CASCADE” to disable its foreign keys. For example: ALTER TABLE student DROPPRIMARYKEY CASCADE; In above case foreign key constraint on result table will be deleted too. 17
  • 18. DISABLE Constraint •DROPconstraint: ALTER TABLE <table_name> DISABLECONSTRAINT<constraint_name>CASCADE; •Apply the “CASCADE” option to disable its dependent integrity constraints. 18
  • 19. ENABLE Constraint •It is used to ENABLE the DISABLED constraints: ALTER TABLE <table_name> ENABLE CONSTRAINT<constraint_name>; 19
  • 20. CASCADE Constraint •The CASCADE constraints clause is used along with the DROPCOLUMN clause. •The CASCADE clause drops all referential integrity constraints that refer to the primary and unique keys defined on the dropped columns. •The CASCADE clause also drops all multicolumn constraints defined on the dropped columns. •Example: ALTER TABLE <table_name> DROP(<constraint_name(s)>)CASCADECONSTRAINTS; 20