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

What's hot (20)

SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Commands of DML in SQL
Commands of DML in SQLCommands of DML in SQL
Commands of DML in SQL
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
Oracle: PLSQL Introduction
Oracle: PLSQL IntroductionOracle: PLSQL Introduction
Oracle: PLSQL Introduction
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
 
Les13
Les13Les13
Les13
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
Sql commands
Sql commandsSql commands
Sql commands
 
My sql Syntax
My sql SyntaxMy sql Syntax
My sql Syntax
 
Prabu's sql quries
Prabu's sql quries Prabu's sql quries
Prabu's sql quries
 
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 delete, truncate, drop statements
Sql delete, truncate, drop statementsSql delete, truncate, drop statements
Sql delete, truncate, drop statements
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
Oracle sql material
Oracle sql materialOracle sql material
Oracle sql material
 
Les10
Les10Les10
Les10
 

Similar to Oracle: 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.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: Commands (20)

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
 
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
 
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
 
ADBMS Unit-II c
ADBMS Unit-II cADBMS Unit-II c
ADBMS Unit-II c
 
My sql
My sqlMy sql
My sql
 
SQL report
SQL reportSQL report
SQL report
 

More from oracle content

More from oracle content (13)

Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
Oracle: PLSQL Introduction
Oracle: PLSQL IntroductionOracle: PLSQL Introduction
Oracle: PLSQL Introduction
 
Oracle : DML
Oracle : DMLOracle : DML
Oracle : DML
 
Oracle: Programs
Oracle: ProgramsOracle: Programs
Oracle: Programs
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 
Oracle:Cursors
Oracle:CursorsOracle:Cursors
Oracle:Cursors
 
Oracle: Control Structures
Oracle:  Control StructuresOracle:  Control Structures
Oracle: Control Structures
 
Oracle: Dw Design
Oracle: Dw DesignOracle: Dw Design
Oracle: Dw Design
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
Oracle Warehouse
Oracle WarehouseOracle Warehouse
Oracle Warehouse
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Oracle: New Plsql
Oracle: New PlsqlOracle: New Plsql
Oracle: New Plsql
 
Oracle: Fundamental Of Dw
Oracle: Fundamental Of DwOracle: Fundamental Of Dw
Oracle: Fundamental Of Dw
 

Recently uploaded

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
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
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Recently uploaded (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
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...
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

Oracle: Commands

  • 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