SlideShare a Scribd company logo
1 of 26
1 Using ORACLE® Data Definition Language (Creating our sample database)   Indexes and Views
2 DATA DEFINATION LANGUAGE Data Definition language abbreviated as DDL refers to the set of commands used to define the data containers in Oracle like Tables and also defining Views and Indexes. Basically there are 3 DDL commands viz:
3 THE CREATE COMMAND The “CREATE” command can be used to create a table, view, index etc. Let us look at creating a table: In order to create a table a user must have the privileges to create tables i.e. 			The “CREATE TABLE” privilege. The basic syntax to create a table is : CREATE TABLE [schema.]TABLENAME 			            ( colm1_name datatype[size] [colm_level_constraint], 		                                colm2_name datatype[size]… 					. 					.	 		 	              [table level constraints] 			              [ON COMMIT clause] or [ON UPDATE clause] }; Constraints enforce certain rules on the table to maintain data integrity and quality.
4 NAMING CONVENTIONS Within the table definition the user has to specify : Table name. Column name. Column data type. Size of the column. Constraint [ if any]. The naming conventions for the table name and column names are: Must begin with a character(either in lower or upper case) and may be up to 30 characters long. Can contain a combination of alphabets(A-Z & a-z), numbers(0-9),_,   $ and #. Must not be a previously specified name for another oracle object owned by the same user and must not be an Oracle reserved keyword.
5 DATATYPES Following the column name every column must be specified with a data type. Data types provided by Oracle are:
6 CONSTRAINTS
7 THE CREATE COMMAND Another keyword “DEFAULT” is used to specify the value to be inserted if the user does not enter a value.
8 THE CREATE COMMAND Constraints can be given a name or the Oracle server itself names the contraints in a SYS_Cn format where n stands for the constraint number. To name a constraint the syntax is : CREATE TABLE TABLE_NAME(colm1_name datatype[size] [CONSTRAINT] constraint_name1 constraint,						column level constraint . . CONSTRAINT constraint_name2 constraint(colm2_name)); table level constraint Constraints can either be defined at column level or table level. You can notice that constraint_name1 is defined at a column level and constraint_name2 is defined at a table level. All constraints except “NOT NULL” can be defined at table level.
9 EXAMPLE TABLE CREATION To get a better grasp of things let us create a set of example tables covering one by one the points leant in the previous slides: EXAMPLE 1: CREATE TABLE MySchema.InfoTable (	name varchar2(15),  				age number(3),  				phone number(10)	   );
10 TABLE WITH CONSTRAINTS The previous table contained no constraints .We will create a new table with the following constraints:
11 TABLE WITH CONSTRAINTS The SQL code for creating the above table is: CREATE TABLE ConTable 	( 	ID number(5), 	name varchar2(15)CONSTRAINTS ConTable_name NOT NULL, 	age number(3) DEFAULT 18, 	phone number(10)CONSTRAINTS ConTable_phone_unique UNIQUE, 	city varchar2(15)CONSTRAINTS ConTable_city_check 	CHECK(city IN( ‘MUMBAI’,’PUNE’,’HYDERABAD’)), 	CONSTRAINTS ConTable_pk PRIMARY KEY (ID), ConTable_fk FOREIGN KEY(ID) REFERENCES CustDetails(ID) 	);  	     Here we have defined NOT NULL constraint at a column level while the PRIMARY KEY 	    	     constraint at the table level.
12 CREATING TABLES USING THE AS CLAUSE (SUBQUERY) In the previous examples we have created tables but not populated them. There a method of creating tables and populating them with data from other tables. It is the method of using subqueries: SYNTAX: CREATE TABLE TABLE_NAME (colm_namedatatype(size) [constraint]… 			… 			.. ) AS SUBQUERY(the SELECT statement);
13 CREATING TABLES USING THE AS CLAUSE (SUBQUERY) Consider the table in EXAMPLE1 to be populated with the data: Now we will create a table InfoTable40 and populate it with data  from the above table.  EXAMPLE3: CREATE TABLE InfoTable40 AS ( SELECT * FROM Infotable WHERE age=40); On viewing the data in InfoTable40 we see: i.e.  It contains the rows from InfoTable with age = 40 as per  the SELECT subquery. Hence we have created and populated a table in one statement.
14 ALTERING TABLES Once a table is created it structure can be altered using the ALTER command. Using the alter command we can Add a column or constraint or Default value. Modify a column. Delete a column. The ALTER command can be used along with the following keywords:
15 ALTERING THE EXAMPLE TABLE	 The SYNTAX for ALTER command is: ALTER TABLE TABLE_NAME [ADD/MODIFY/DROP] (colm_namedatatype[size] [constraint]); Consider the EXAMPLE1 table InfoTable: We will alter the table in three steps: First modify the precision of “age” column to 4. Add a new column “city”. Drop the column “phone” .
16 ALTERING TABLES MODIFYING: ALTER TABLE InfoTable MODIFY(age number(4) DEFAULT 20); ADDING: ALTER TABLE InfoTable ADD(city varchar2(15)); DROPPING: ALTER TABLE InfoTable drop(phone);
17 DROPPING TABLES Once a tables is created and populated, we can drop the table using the DROP command. Once the DROP command has been exercised : It cannot be reversed and the data and structure are lost permanently  Also dropping a table renders the views and indexed referring to the table invalid. Also drops the all its constraints. The SYNTAX for the DROP command is: DROP TABLE TABLE_NAME; EXAMPLE: DROP TABLE InfoTable; DESC InfoTable;
18 CREATING OTHER ORACLE OBJECTS The CREATE command can not only be used to create tables but also other database objects like views, indexes and sequences.
19 CREATING A VIEW A view is a logical representation of a subset of data from one or more tables/views. The advantages of a view are: Restrict data access. Simplifying queries for the end user. Displaying the same data in different views. A view can be updatable (manipulate base table using view) or a read only view. A view can be created using a CREATE command. The SYNTAX to create a view is: CREATE  [OR REPLACE] VIEW VIEW_NAME [ alias , alias…] AS SUBQUERY                     a select statement [WITH CHECK OPTION]      specifies the only the rows displayable in the view can be inserted or updated [WITH READ ONLY]             specifies the DML operations cannot be performed using the view.
20 EXAMPLE VIEW CREATION CREATE VIEW InfoTable_View AS SELECT * FROM InfoTable WHERE age = 40; SELECT * FROM InfoTable_View; VIEW WITH ALIAS: CREATE VIEW InfoTable_ViewAlias AS SELECT name ENAME,ageEAGE,phone CONTACT_NO FROM InfoTable WHERE age = 40; SELECT * FROM InfoTable_ViewAlias ;
21 ALTERING AND DROPPING A VIEW ALTERING the InfoTable_View view: CREATE OR REPLACE VIEW InfoTable_View AS SELECT * FROM InfoTable WHERE age > 40;  SELECT * FROM InfoTable_View; DROPPING A VIEW: DROP VIEW InfoTable_View; SELECT * FROM InfoTable_View;
22 CREATING AN SEQUENCE A sequence is an object that can generate a series of numbers. A sequence can be shared by other objects and it speeds up accessing a sequence if cached in memory. The basic syntax to create an sequence is: CREATE SEQUENCE SEQUENCE_NAME [INCREMENT BY n]		- value by which it must be incremented [START WITH n]		- value from which sequence generation must begin. [MINVALUE n]		- specifies a maximum value the sequence can generate. Default is 10^26 for ascending 			   sequence and 1 for descending sequence. [MAXVALUE n]		- specified the minimum value for a sequence generate. Default is 1 for ascending sequence 			   and 10^26 for descending sequence. [CYCLE / NOCYCLE ]		- specifies whether once maximum value is reached can it cycle from the start value. [CACHE n / NOCACHE ]	- specifies how many sequence values can be stored in the cache for quick access. 	        Once a sequence is created we can assess it using two methods: CURRVAL : returns the current value of the sequence number. NEXTVAL : returns the next value in the sequence and it returns a unique value even when being used by multiple tables.
23 EXAMPLE SEQUENCE We create an example sequence. CREATE SEQUENCE ascseq INCREMENT BY 5 MAXVALUE 100 CYCLE NOCACHE; The above sequence an be accessed by ascseq.currval or ascseq.nextval and can be used to generate a primary key. USAGE IN A TABLE: INSERT INTO ConTable VALUES(ascseq.nextval,'bill' ,40,9000666000 ,'PUNE' );
24 ALTERING AND DROPPING SEQUENCE To alter a sequence we use the ALTER commnad. SYNTAX:					EXAMPLE: ALTER SEQUENCE SEQUENCE_NAME		ALTER SEQUENCE ascseq [INCREMENT BY n]				INCREMENT BY 10		 [MINVALUE n] 					 [MAXVALUE n]			 	MAXVALUE 200	 [CYCLE / NOCYCLE ]				NOCYCLE 		 [CACHE n / NOCACHE ];			CACHE 10; The START WITH parameter cannot be altered once a sequence is created.nly future values will be affected. Hence the MAXVALUE must be greater than at least the value last generated. DROPPING A SEQUENCE:			EXAMPLE: DROP SEQUENCE SEQUENCE_NAME;		DROP SEQUENCE ascseq;
25 CREATING AN INDEX An index is an object that creates a rapid path of access to the rows of specified tables and helps in improving the retrieval of data . The index is independent of the table and is used and maintained by the Oracle server. Oracle server automatically creates indexes on columns of a table having Primary key or Unique  as constraints. Users can manually create Indexes for other non key columns. SYNTAX:						Index on phone column: CREATE INDEX INDEX_NAME				CREATE INDEX ConTable_Idx ON TABLE_NAME( column1,…[column n]);		ON ConTable (phone); DROPPING AN INDEX: DROP INDEX INDEX_NAME;				DROP INDEX ConTable_Idx; Create an Index only when the column contains a large number of rows, is frequently used and is present in queries returning a large number of rows to avoid wastage of resources.
THANK YOU 26 THANK YOU FOR VIEWING THIS PRESENTATION FOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING , please visit:   www.dataminingtools.net

More Related Content

What's hot (20)

SQL
SQLSQL
SQL
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Python datetime
Python datetimePython datetime
Python datetime
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
Effective Java - Enum and Annotations
Effective Java - Enum and AnnotationsEffective Java - Enum and Annotations
Effective Java - Enum and Annotations
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
HTML: Tables and Forms
HTML: Tables and FormsHTML: Tables and Forms
HTML: Tables and Forms
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
 
Oracle Database Trigger
Oracle Database TriggerOracle Database Trigger
Oracle Database Trigger
 
SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and Operators
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Window functions with SQL Server 2016
Window functions with SQL Server 2016Window functions with SQL Server 2016
Window functions with SQL Server 2016
 
Oracle: DML
Oracle: DMLOracle: DML
Oracle: DML
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
 

Viewers also liked

Part 6 ddl dan dml (case studiies)
Part 6  ddl dan dml (case studiies)Part 6  ddl dan dml (case studiies)
Part 6 ddl dan dml (case studiies)Denny Yahya
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptgourav kottawar
 
Data definition language (ddl)
Data definition language (ddl)Data definition language (ddl)
Data definition language (ddl)Dex Winadha
 
Oracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick Learning
Oracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick LearningOracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick Learning
Oracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick LearningeVideoTuition
 
Part 7 ddl dan dml lant..retriving data up
Part 7  ddl dan dml lant..retriving data upPart 7  ddl dan dml lant..retriving data up
Part 7 ddl dan dml lant..retriving data upDenny Yahya
 
Sql joins inner join self join outer joins
Sql joins inner join self join outer joinsSql joins inner join self join outer joins
Sql joins inner join self join outer joinsDeepthi Rachumallu
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Serverprogrammings guru
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query OptimizationBrian Gallagher
 
Huidige status van de testtaal TTCN-3
Huidige status van de testtaal TTCN-3Huidige status van de testtaal TTCN-3
Huidige status van de testtaal TTCN-3Erik Altena
 
建築師法修正草案總說明
建築師法修正草案總說明建築師法修正草案總說明
建築師法修正草案總說明Filip Yang
 
MS SQL SERVER: Microsoft naive bayes algorithm
MS SQL SERVER: Microsoft naive bayes algorithmMS SQL SERVER: Microsoft naive bayes algorithm
MS SQL SERVER: Microsoft naive bayes algorithmDataminingTools Inc
 

Viewers also liked (20)

SQL DDL
SQL DDLSQL DDL
SQL DDL
 
Part 6 ddl dan dml (case studiies)
Part 6  ddl dan dml (case studiies)Part 6  ddl dan dml (case studiies)
Part 6 ddl dan dml (case studiies)
 
DDL DML sysytems
DDL DML sysytemsDDL DML sysytems
DDL DML sysytems
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) ppt
 
Data definition language (ddl)
Data definition language (ddl)Data definition language (ddl)
Data definition language (ddl)
 
Dml and ddl
Dml and ddlDml and ddl
Dml and ddl
 
Oracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick Learning
Oracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick LearningOracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick Learning
Oracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick Learning
 
1 ddl
1 ddl1 ddl
1 ddl
 
Part 7 ddl dan dml lant..retriving data up
Part 7  ddl dan dml lant..retriving data upPart 7  ddl dan dml lant..retriving data up
Part 7 ddl dan dml lant..retriving data up
 
Sql joins inner join self join outer joins
Sql joins inner join self join outer joinsSql joins inner join self join outer joins
Sql joins inner join self join outer joins
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
 
DML Commands
DML CommandsDML Commands
DML Commands
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query Optimization
 
Huidige status van de testtaal TTCN-3
Huidige status van de testtaal TTCN-3Huidige status van de testtaal TTCN-3
Huidige status van de testtaal TTCN-3
 
R Statistics
R StatisticsR Statistics
R Statistics
 
Association Rules
Association RulesAssociation Rules
Association Rules
 
LISP: Scope and extent in lisp
LISP: Scope and extent in lispLISP: Scope and extent in lisp
LISP: Scope and extent in lisp
 
建築師法修正草案總說明
建築師法修正草案總說明建築師法修正草案總說明
建築師法修正草案總說明
 
MS SQL SERVER: Microsoft naive bayes algorithm
MS SQL SERVER: Microsoft naive bayes algorithmMS SQL SERVER: Microsoft naive bayes algorithm
MS SQL SERVER: Microsoft naive bayes algorithm
 
Txomin Hartz Txikia
Txomin Hartz TxikiaTxomin Hartz Txikia
Txomin Hartz Txikia
 

Similar to Oracle: DDL

Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commandsBelle Wx
 
Unit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptxUnit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptxPetroJoe
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptxSiddhantBhardwaj26
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasadpaddu123
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasadpaddu123
 
Exploring collections with example
Exploring collections with exampleExploring collections with example
Exploring collections with examplepranav kumar verma
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETEAbrar ali
 
Creating, altering and dropping tables
Creating, altering and dropping tablesCreating, altering and dropping tables
Creating, altering and dropping tablespunu_82
 
1.Implementing_Data_Integrity.pdf
1.Implementing_Data_Integrity.pdf1.Implementing_Data_Integrity.pdf
1.Implementing_Data_Integrity.pdfdiaa46
 

Similar to Oracle: DDL (20)

Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
Unit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptxUnit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptx
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
 
Sql commands
Sql commandsSql commands
Sql commands
 
Module 3
Module 3Module 3
Module 3
 
DBMS LAB M.docx
DBMS LAB M.docxDBMS LAB M.docx
DBMS LAB M.docx
 
chapter 8 SQL.ppt
chapter 8 SQL.pptchapter 8 SQL.ppt
chapter 8 SQL.ppt
 
Lab
LabLab
Lab
 
Les10 Creating And Managing Tables
Les10 Creating And Managing TablesLes10 Creating And Managing Tables
Les10 Creating And Managing Tables
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
DBMS.pdf
DBMS.pdfDBMS.pdf
DBMS.pdf
 
Exploring collections with example
Exploring collections with exampleExploring collections with example
Exploring collections with example
 
Les10
Les10Les10
Les10
 
Sql wksht-2
Sql wksht-2Sql wksht-2
Sql wksht-2
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
Creating, altering and dropping tables
Creating, altering and dropping tablesCreating, altering and dropping tables
Creating, altering and dropping tables
 
Sql basics
Sql  basicsSql  basics
Sql basics
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
 
1.Implementing_Data_Integrity.pdf
1.Implementing_Data_Integrity.pdf1.Implementing_Data_Integrity.pdf
1.Implementing_Data_Integrity.pdf
 

More from DataminingTools Inc

AI: Introduction to artificial intelligence
AI: Introduction to artificial intelligenceAI: Introduction to artificial intelligence
AI: Introduction to artificial intelligenceDataminingTools Inc
 
Data Mining: Text and web mining
Data Mining: Text and web miningData Mining: Text and web mining
Data Mining: Text and web miningDataminingTools Inc
 
Data Mining: Mining stream time series and sequence data
Data Mining: Mining stream time series and sequence dataData Mining: Mining stream time series and sequence data
Data Mining: Mining stream time series and sequence dataDataminingTools Inc
 
Data Mining: Mining ,associations, and correlations
Data Mining: Mining ,associations, and correlationsData Mining: Mining ,associations, and correlations
Data Mining: Mining ,associations, and correlationsDataminingTools Inc
 
Data Mining: Graph mining and social network analysis
Data Mining: Graph mining and social network analysisData Mining: Graph mining and social network analysis
Data Mining: Graph mining and social network analysisDataminingTools Inc
 
Data warehouse and olap technology
Data warehouse and olap technologyData warehouse and olap technology
Data warehouse and olap technologyDataminingTools Inc
 

More from DataminingTools Inc (20)

Terminology Machine Learning
Terminology Machine LearningTerminology Machine Learning
Terminology Machine Learning
 
Techniques Machine Learning
Techniques Machine LearningTechniques Machine Learning
Techniques Machine Learning
 
Machine learning Introduction
Machine learning IntroductionMachine learning Introduction
Machine learning Introduction
 
Areas of machine leanring
Areas of machine leanringAreas of machine leanring
Areas of machine leanring
 
AI: Planning and AI
AI: Planning and AIAI: Planning and AI
AI: Planning and AI
 
AI: Logic in AI 2
AI: Logic in AI 2AI: Logic in AI 2
AI: Logic in AI 2
 
AI: Logic in AI
AI: Logic in AIAI: Logic in AI
AI: Logic in AI
 
AI: Learning in AI 2
AI: Learning in AI 2AI: Learning in AI 2
AI: Learning in AI 2
 
AI: Learning in AI
AI: Learning in AI AI: Learning in AI
AI: Learning in AI
 
AI: Introduction to artificial intelligence
AI: Introduction to artificial intelligenceAI: Introduction to artificial intelligence
AI: Introduction to artificial intelligence
 
AI: Belief Networks
AI: Belief NetworksAI: Belief Networks
AI: Belief Networks
 
AI: AI & Searching
AI: AI & SearchingAI: AI & Searching
AI: AI & Searching
 
AI: AI & Problem Solving
AI: AI & Problem SolvingAI: AI & Problem Solving
AI: AI & Problem Solving
 
Data Mining: Text and web mining
Data Mining: Text and web miningData Mining: Text and web mining
Data Mining: Text and web mining
 
Data Mining: Outlier analysis
Data Mining: Outlier analysisData Mining: Outlier analysis
Data Mining: Outlier analysis
 
Data Mining: Mining stream time series and sequence data
Data Mining: Mining stream time series and sequence dataData Mining: Mining stream time series and sequence data
Data Mining: Mining stream time series and sequence data
 
Data Mining: Mining ,associations, and correlations
Data Mining: Mining ,associations, and correlationsData Mining: Mining ,associations, and correlations
Data Mining: Mining ,associations, and correlations
 
Data Mining: Graph mining and social network analysis
Data Mining: Graph mining and social network analysisData Mining: Graph mining and social network analysis
Data Mining: Graph mining and social network analysis
 
Data warehouse and olap technology
Data warehouse and olap technologyData warehouse and olap technology
Data warehouse and olap technology
 
Data Mining: Data processing
Data Mining: Data processingData Mining: Data processing
Data Mining: Data processing
 

Recently uploaded

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Recently uploaded (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Oracle: DDL

  • 1. 1 Using ORACLE® Data Definition Language (Creating our sample database) Indexes and Views
  • 2. 2 DATA DEFINATION LANGUAGE Data Definition language abbreviated as DDL refers to the set of commands used to define the data containers in Oracle like Tables and also defining Views and Indexes. Basically there are 3 DDL commands viz:
  • 3. 3 THE CREATE COMMAND The “CREATE” command can be used to create a table, view, index etc. Let us look at creating a table: In order to create a table a user must have the privileges to create tables i.e. The “CREATE TABLE” privilege. The basic syntax to create a table is : CREATE TABLE [schema.]TABLENAME ( colm1_name datatype[size] [colm_level_constraint], colm2_name datatype[size]… . . [table level constraints] [ON COMMIT clause] or [ON UPDATE clause] }; Constraints enforce certain rules on the table to maintain data integrity and quality.
  • 4. 4 NAMING CONVENTIONS Within the table definition the user has to specify : Table name. Column name. Column data type. Size of the column. Constraint [ if any]. The naming conventions for the table name and column names are: Must begin with a character(either in lower or upper case) and may be up to 30 characters long. Can contain a combination of alphabets(A-Z & a-z), numbers(0-9),_, $ and #. Must not be a previously specified name for another oracle object owned by the same user and must not be an Oracle reserved keyword.
  • 5. 5 DATATYPES Following the column name every column must be specified with a data type. Data types provided by Oracle are:
  • 7. 7 THE CREATE COMMAND Another keyword “DEFAULT” is used to specify the value to be inserted if the user does not enter a value.
  • 8. 8 THE CREATE COMMAND Constraints can be given a name or the Oracle server itself names the contraints in a SYS_Cn format where n stands for the constraint number. To name a constraint the syntax is : CREATE TABLE TABLE_NAME(colm1_name datatype[size] [CONSTRAINT] constraint_name1 constraint, column level constraint . . CONSTRAINT constraint_name2 constraint(colm2_name)); table level constraint Constraints can either be defined at column level or table level. You can notice that constraint_name1 is defined at a column level and constraint_name2 is defined at a table level. All constraints except “NOT NULL” can be defined at table level.
  • 9. 9 EXAMPLE TABLE CREATION To get a better grasp of things let us create a set of example tables covering one by one the points leant in the previous slides: EXAMPLE 1: CREATE TABLE MySchema.InfoTable ( name varchar2(15), age number(3), phone number(10) );
  • 10. 10 TABLE WITH CONSTRAINTS The previous table contained no constraints .We will create a new table with the following constraints:
  • 11. 11 TABLE WITH CONSTRAINTS The SQL code for creating the above table is: CREATE TABLE ConTable ( ID number(5), name varchar2(15)CONSTRAINTS ConTable_name NOT NULL, age number(3) DEFAULT 18, phone number(10)CONSTRAINTS ConTable_phone_unique UNIQUE, city varchar2(15)CONSTRAINTS ConTable_city_check CHECK(city IN( ‘MUMBAI’,’PUNE’,’HYDERABAD’)), CONSTRAINTS ConTable_pk PRIMARY KEY (ID), ConTable_fk FOREIGN KEY(ID) REFERENCES CustDetails(ID) ); Here we have defined NOT NULL constraint at a column level while the PRIMARY KEY constraint at the table level.
  • 12. 12 CREATING TABLES USING THE AS CLAUSE (SUBQUERY) In the previous examples we have created tables but not populated them. There a method of creating tables and populating them with data from other tables. It is the method of using subqueries: SYNTAX: CREATE TABLE TABLE_NAME (colm_namedatatype(size) [constraint]… … .. ) AS SUBQUERY(the SELECT statement);
  • 13. 13 CREATING TABLES USING THE AS CLAUSE (SUBQUERY) Consider the table in EXAMPLE1 to be populated with the data: Now we will create a table InfoTable40 and populate it with data from the above table. EXAMPLE3: CREATE TABLE InfoTable40 AS ( SELECT * FROM Infotable WHERE age=40); On viewing the data in InfoTable40 we see: i.e. It contains the rows from InfoTable with age = 40 as per the SELECT subquery. Hence we have created and populated a table in one statement.
  • 14. 14 ALTERING TABLES Once a table is created it structure can be altered using the ALTER command. Using the alter command we can Add a column or constraint or Default value. Modify a column. Delete a column. The ALTER command can be used along with the following keywords:
  • 15. 15 ALTERING THE EXAMPLE TABLE The SYNTAX for ALTER command is: ALTER TABLE TABLE_NAME [ADD/MODIFY/DROP] (colm_namedatatype[size] [constraint]); Consider the EXAMPLE1 table InfoTable: We will alter the table in three steps: First modify the precision of “age” column to 4. Add a new column “city”. Drop the column “phone” .
  • 16. 16 ALTERING TABLES MODIFYING: ALTER TABLE InfoTable MODIFY(age number(4) DEFAULT 20); ADDING: ALTER TABLE InfoTable ADD(city varchar2(15)); DROPPING: ALTER TABLE InfoTable drop(phone);
  • 17. 17 DROPPING TABLES Once a tables is created and populated, we can drop the table using the DROP command. Once the DROP command has been exercised : It cannot be reversed and the data and structure are lost permanently Also dropping a table renders the views and indexed referring to the table invalid. Also drops the all its constraints. The SYNTAX for the DROP command is: DROP TABLE TABLE_NAME; EXAMPLE: DROP TABLE InfoTable; DESC InfoTable;
  • 18. 18 CREATING OTHER ORACLE OBJECTS The CREATE command can not only be used to create tables but also other database objects like views, indexes and sequences.
  • 19. 19 CREATING A VIEW A view is a logical representation of a subset of data from one or more tables/views. The advantages of a view are: Restrict data access. Simplifying queries for the end user. Displaying the same data in different views. A view can be updatable (manipulate base table using view) or a read only view. A view can be created using a CREATE command. The SYNTAX to create a view is: CREATE [OR REPLACE] VIEW VIEW_NAME [ alias , alias…] AS SUBQUERY a select statement [WITH CHECK OPTION] specifies the only the rows displayable in the view can be inserted or updated [WITH READ ONLY] specifies the DML operations cannot be performed using the view.
  • 20. 20 EXAMPLE VIEW CREATION CREATE VIEW InfoTable_View AS SELECT * FROM InfoTable WHERE age = 40; SELECT * FROM InfoTable_View; VIEW WITH ALIAS: CREATE VIEW InfoTable_ViewAlias AS SELECT name ENAME,ageEAGE,phone CONTACT_NO FROM InfoTable WHERE age = 40; SELECT * FROM InfoTable_ViewAlias ;
  • 21. 21 ALTERING AND DROPPING A VIEW ALTERING the InfoTable_View view: CREATE OR REPLACE VIEW InfoTable_View AS SELECT * FROM InfoTable WHERE age > 40; SELECT * FROM InfoTable_View; DROPPING A VIEW: DROP VIEW InfoTable_View; SELECT * FROM InfoTable_View;
  • 22. 22 CREATING AN SEQUENCE A sequence is an object that can generate a series of numbers. A sequence can be shared by other objects and it speeds up accessing a sequence if cached in memory. The basic syntax to create an sequence is: CREATE SEQUENCE SEQUENCE_NAME [INCREMENT BY n] - value by which it must be incremented [START WITH n] - value from which sequence generation must begin. [MINVALUE n] - specifies a maximum value the sequence can generate. Default is 10^26 for ascending sequence and 1 for descending sequence. [MAXVALUE n] - specified the minimum value for a sequence generate. Default is 1 for ascending sequence and 10^26 for descending sequence. [CYCLE / NOCYCLE ] - specifies whether once maximum value is reached can it cycle from the start value. [CACHE n / NOCACHE ] - specifies how many sequence values can be stored in the cache for quick access. Once a sequence is created we can assess it using two methods: CURRVAL : returns the current value of the sequence number. NEXTVAL : returns the next value in the sequence and it returns a unique value even when being used by multiple tables.
  • 23. 23 EXAMPLE SEQUENCE We create an example sequence. CREATE SEQUENCE ascseq INCREMENT BY 5 MAXVALUE 100 CYCLE NOCACHE; The above sequence an be accessed by ascseq.currval or ascseq.nextval and can be used to generate a primary key. USAGE IN A TABLE: INSERT INTO ConTable VALUES(ascseq.nextval,'bill' ,40,9000666000 ,'PUNE' );
  • 24. 24 ALTERING AND DROPPING SEQUENCE To alter a sequence we use the ALTER commnad. SYNTAX: EXAMPLE: ALTER SEQUENCE SEQUENCE_NAME ALTER SEQUENCE ascseq [INCREMENT BY n] INCREMENT BY 10 [MINVALUE n] [MAXVALUE n] MAXVALUE 200 [CYCLE / NOCYCLE ] NOCYCLE [CACHE n / NOCACHE ]; CACHE 10; The START WITH parameter cannot be altered once a sequence is created.nly future values will be affected. Hence the MAXVALUE must be greater than at least the value last generated. DROPPING A SEQUENCE: EXAMPLE: DROP SEQUENCE SEQUENCE_NAME; DROP SEQUENCE ascseq;
  • 25. 25 CREATING AN INDEX An index is an object that creates a rapid path of access to the rows of specified tables and helps in improving the retrieval of data . The index is independent of the table and is used and maintained by the Oracle server. Oracle server automatically creates indexes on columns of a table having Primary key or Unique as constraints. Users can manually create Indexes for other non key columns. SYNTAX: Index on phone column: CREATE INDEX INDEX_NAME CREATE INDEX ConTable_Idx ON TABLE_NAME( column1,…[column n]); ON ConTable (phone); DROPPING AN INDEX: DROP INDEX INDEX_NAME; DROP INDEX ConTable_Idx; Create an Index only when the column contains a large number of rows, is frequently used and is present in queries returning a large number of rows to avoid wastage of resources.
  • 26. THANK YOU 26 THANK YOU FOR VIEWING THIS PRESENTATION FOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING , please visit: www.dataminingtools.net