SlideShare a Scribd company logo
1Using ORACLE®Data Definition Language(Creating our sample database)  Indexes and Views
2DATA DEFINATION LANGUAGEData 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:
3THE CREATE COMMANDThe “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.
4NAMING CONVENTIONSWithin 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.
5DATATYPESFollowing the column name every column must be specified with a data type. Data types provided by Oracle are:
6CONSTRAINTS
7THE CREATE COMMANDAnother keyword “DEFAULT” is used to specify the value to be inserted if the user does not enter a value.
8THE CREATE COMMANDConstraints 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 constraintConstraints 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.
9EXAMPLE TABLE CREATIONTo 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)	   );
10TABLE WITH CONSTRAINTSThe previous table contained no constraints .We will create a new table with the following constraints:
11TABLE WITH CONSTRAINTSThe 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’)),	CONSTRAINTSConTable_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.
12CREATING 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]…			…			.. )ASSUBQUERY(the SELECT statement);
13CREATING 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 InfoTable40AS( 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.
14ALTERING TABLESOnce a table is created it structure can be altered using the ALTER command.Using the alter command we canAdd a column or constraint or Default value.Modify a column.Delete a column.The ALTER command can be used along with the following keywords:
15ALTERING 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” .
16ALTERING TABLESMODIFYING:ALTER TABLE InfoTable MODIFY(age number(4) DEFAULT 20);ADDING:ALTER TABLE InfoTable ADD(city varchar2(15));DROPPING:ALTER TABLE InfoTable drop(phone);
17DROPPING TABLESOnce 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;
18CREATING OTHER ORACLE OBJECTSThe CREATE command can not only be used to create tables but also other database objects like views, indexes and sequences.
19CREATING A VIEWA 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.
20EXAMPLE VIEW CREATIONCREATE VIEW InfoTable_ViewASSELECT * FROM InfoTable WHERE age = 40;SELECT * FROM InfoTable_View;VIEW WITH ALIAS:CREATE VIEW InfoTable_ViewAliasASSELECT name ENAME,ageEAGE,phone CONTACT_NO FROM InfoTable WHERE age = 40;SELECT * FROM InfoTable_ViewAlias ;
21ALTERING AND DROPPING A VIEWALTERING the InfoTable_View view:CREATE OR REPLACE VIEW InfoTable_ViewASSELECT * FROM InfoTable WHERE age > 40; SELECT * FROM InfoTable_View;DROPPING A VIEW:DROP VIEW InfoTable_View;SELECT * FROM InfoTable_View;
22CREATING AN SEQUENCEA 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.
23EXAMPLE SEQUENCEWe create an example sequence.CREATE SEQUENCE ascseqINCREMENT BY 5MAXVALUE 100CYCLENOCACHE;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' );
24ALTERING AND DROPPING SEQUENCETo 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;
25CREATING AN INDEXAn 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_IdxON 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 YOU26THANK YOU FOR VIEWING THIS PRESENTATIONFOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING ,please visit:  www.dataminingtools.net

More Related Content

PPTX
Oracle: PLSQL Commands
PPTX
Oracle: DDL
PPTX
Oracle: DML
DOCX
Ddl commands
PPTX
DDL,DML,SQL Functions and Joins
PPTX
8. sql
Oracle: PLSQL Commands
Oracle: DDL
Oracle: DML
Ddl commands
DDL,DML,SQL Functions and Joins
8. sql

What's hot (20)

PPTX
SQL(DDL & DML)
PPTX
Commands of DML in SQL
PDF
Database Systems - SQL - DDL Statements (Chapter 3/2)
PPTX
Oracle: PLSQL Introduction
PPTX
Creating database using sql commands
PPT
Sql basics and DDL statements
PPT
PPTX
SQL - DML and DDL Commands
PPTX
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
ODP
ODP
My sql Syntax
ODP
Prabu's sql quries
PPTX
Database Management - Lecture 2 - SQL select, insert, update and delete
PDF
Sql delete, truncate, drop statements
PPT
Sql dml & tcl 2
PDF
Database Systems - SQL - DDL Statements (Chapter 3/3)
PPT
SQL Tutorial - Basic Commands
DOC
Oracle sql material
PPT
SQL(DDL & DML)
Commands of DML in SQL
Database Systems - SQL - DDL Statements (Chapter 3/2)
Oracle: PLSQL Introduction
Creating database using sql commands
Sql basics and DDL statements
SQL - DML and DDL Commands
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
My sql Syntax
Prabu's sql quries
Database Management - Lecture 2 - SQL select, insert, update and delete
Sql delete, truncate, drop statements
Sql dml & tcl 2
Database Systems - SQL - DDL Statements (Chapter 3/3)
SQL Tutorial - Basic Commands
Oracle sql material
Ad

Similar to Oracle: Commands (20)

PDF
Intruduction to SQL.Structured Query Language(SQL}
PPTX
Less08_Schema Advanced Databases and Management.pptx
PPT
Lec 1 = introduction to structured query language (sql)
PPT
15925 structured query
DOC
Oracle SQL AND PL/SQL
PPT
Introduction to Structured Query Language (SQL).ppt
PPT
SQL WORKSHOP::Lecture 10
PPT
Introduction to Structured Query Language (SQL) (1).ppt
PPT
DDL. data defination language for creating database
PPTX
Relational Database Language.pptx
PPT
Les10[1]Creating and Managing Tables
PPTX
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
PPT
Introduction to structured query language (sql)
PDF
Rdbms day3
PPT
Oracle Sql & PLSQL Complete guide
PPT
Sql tables
PPT
Sql tables
PDF
DBMS_ddlVFSBFSBS22222222222222222222222222222222222
PDF
STRUCTURED QUERY LANGUAGE
DOC
Dbms lab Manual
Intruduction to SQL.Structured Query Language(SQL}
Less08_Schema Advanced Databases and Management.pptx
Lec 1 = introduction to structured query language (sql)
15925 structured query
Oracle SQL AND PL/SQL
Introduction to Structured Query Language (SQL).ppt
SQL WORKSHOP::Lecture 10
Introduction to Structured Query Language (SQL) (1).ppt
DDL. data defination language for creating database
Relational Database Language.pptx
Les10[1]Creating and Managing Tables
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
Introduction to structured query language (sql)
Rdbms day3
Oracle Sql & PLSQL Complete guide
Sql tables
Sql tables
DBMS_ddlVFSBFSBS22222222222222222222222222222222222
STRUCTURED QUERY LANGUAGE
Dbms lab Manual
Ad

More from oracle content (13)

PPTX
Oracle: Procedures
PPTX
Oracle: PLSQL Introduction
PPTX
Oracle : DML
PPTX
Oracle: Programs
PPTX
Oracle: Joins
PPTX
Oracle:Cursors
PPTX
Oracle: Control Structures
PPTX
Oracle: Dw Design
PPTX
Oracle: Basic SQL
PPTX
Oracle Warehouse
PPTX
Oracle: Functions
PPT
Oracle: New Plsql
PPTX
Oracle: Fundamental Of Dw
Oracle: Procedures
Oracle: PLSQL Introduction
Oracle : DML
Oracle: Programs
Oracle: Joins
Oracle:Cursors
Oracle: Control Structures
Oracle: Dw Design
Oracle: Basic SQL
Oracle Warehouse
Oracle: Functions
Oracle: New Plsql
Oracle: Fundamental Of Dw

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
Teaching material agriculture food technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Empathic Computing: Creating Shared Understanding
PDF
cuic standard and advanced reporting.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
A Presentation on Artificial Intelligence
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Teaching material agriculture food technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Programs and apps: productivity, graphics, security and other tools
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Per capita expenditure prediction using model stacking based on satellite ima...
The AUB Centre for AI in Media Proposal.docx
Building Integrated photovoltaic BIPV_UPV.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Chapter 3 Spatial Domain Image Processing.pdf
Approach and Philosophy of On baking technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Review of recent advances in non-invasive hemoglobin estimation
Encapsulation_ Review paper, used for researhc scholars
Empathic Computing: Creating Shared Understanding
cuic standard and advanced reporting.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
A Presentation on Artificial Intelligence

Oracle: Commands

  • 1. 1Using ORACLE®Data Definition Language(Creating our sample database) Indexes and Views
  • 2. 2DATA DEFINATION LANGUAGEData 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. 3THE CREATE COMMANDThe “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. 4NAMING CONVENTIONSWithin 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. 5DATATYPESFollowing the column name every column must be specified with a data type. Data types provided by Oracle are:
  • 7. 7THE CREATE COMMANDAnother keyword “DEFAULT” is used to specify the value to be inserted if the user does not enter a value.
  • 8. 8THE CREATE COMMANDConstraints 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 constraintConstraints 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. 9EXAMPLE TABLE CREATIONTo 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. 10TABLE WITH CONSTRAINTSThe previous table contained no constraints .We will create a new table with the following constraints:
  • 11. 11TABLE WITH CONSTRAINTSThe 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’)), CONSTRAINTSConTable_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. 12CREATING 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]… … .. )ASSUBQUERY(the SELECT statement);
  • 13. 13CREATING 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 InfoTable40AS( 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. 14ALTERING TABLESOnce a table is created it structure can be altered using the ALTER command.Using the alter command we canAdd 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. 15ALTERING 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. 16ALTERING TABLESMODIFYING:ALTER TABLE InfoTable MODIFY(age number(4) DEFAULT 20);ADDING:ALTER TABLE InfoTable ADD(city varchar2(15));DROPPING:ALTER TABLE InfoTable drop(phone);
  • 17. 17DROPPING TABLESOnce 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. 18CREATING OTHER ORACLE OBJECTSThe CREATE command can not only be used to create tables but also other database objects like views, indexes and sequences.
  • 19. 19CREATING A VIEWA 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. 20EXAMPLE VIEW CREATIONCREATE VIEW InfoTable_ViewASSELECT * FROM InfoTable WHERE age = 40;SELECT * FROM InfoTable_View;VIEW WITH ALIAS:CREATE VIEW InfoTable_ViewAliasASSELECT name ENAME,ageEAGE,phone CONTACT_NO FROM InfoTable WHERE age = 40;SELECT * FROM InfoTable_ViewAlias ;
  • 21. 21ALTERING AND DROPPING A VIEWALTERING the InfoTable_View view:CREATE OR REPLACE VIEW InfoTable_ViewASSELECT * FROM InfoTable WHERE age > 40; SELECT * FROM InfoTable_View;DROPPING A VIEW:DROP VIEW InfoTable_View;SELECT * FROM InfoTable_View;
  • 22. 22CREATING AN SEQUENCEA 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. 23EXAMPLE SEQUENCEWe create an example sequence.CREATE SEQUENCE ascseqINCREMENT BY 5MAXVALUE 100CYCLENOCACHE;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. 24ALTERING AND DROPPING SEQUENCETo 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. 25CREATING AN INDEXAn 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_IdxON 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 YOU26THANK YOU FOR VIEWING THIS PRESENTATIONFOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING ,please visit: www.dataminingtools.net