SlideShare a Scribd company logo
ADBMS
Unit – II
Data Definition Language (DDL)
Naming Rules and Conventions
• A table is an object that can store data in an Oracle database.
• Create table  must specify table name, name of each column name
with data type with size of each column name.
• Oracle provides different constraints to specify a primary or a
composite key for the table.
• Define a foreign key in a table  references a primary key in another
table.
• To set data validation rules for each column and specify a column
allows NULL values with unique values only.
• Table and Column names  1 to 30 characters long  (A-Z,a-z,0-9, $, _ ,#).
• Names are not case sensitive.
• Oracle stores all object names in uppercase in its data dictionary and server-
reserved word can’t be used.
• Spaces and hyphens aren’t allowed.
ADBMS Unit-II b
Data Types
• When a table is created, each column in the table is assigned a data
type.
• It specifies the type of data that will be stored in that column.
• It also help to optimize storage space.
Varchar2 (Oracle9i) / Varchar (Latest)
• It is a character data type to store variable-length alphanumeric data
in a column.
• VARCHAR is synonymous with VARCHAR2 but it could be a separate
data type with different semantics in the future.
• Maximum size  4000 characters in Oracle 9i
• Minimum size  1 character.
• The size is specified within parentheses.
• If the data are smaller than the specified size, only the data value is
stored and trailing spaces aren’t added to the value.
• Spaces aren’t added to make its length equal to the size of the
column.
• If a value longer that the specified size is entered, however, an error is
generated.
• The longer values aren’t truncated.
Char
• It is a character data type to store fixed-length alphanumeric data in a
column.
• Maximum size  2000 characters (previous version  255
characters).
• Minimum size  1 character.
• If the value is smaller than the specified size, is entered, trailing
spaces are added to make its length equal to the specified length.
• If the value is longer than the specified size, an error occurs.
• It is appropriate for fixed-length values.
• The Char type uses the storage more efficiently and process data
faster than the Varchar2 type.
• In Oracle9i, the Char type can also take CHAR or BYTE parameters.
• Each Char may take up 1 to 4 bytes.
• Latest version not supported byte and char similiar character name
updated in current version.
Number
• It is used to store negative, positive, integer, fixed-decimal and
floating-point numbers.
• It is used for any column names and its precision and scale can be
specified.
• Precision  Total number of significant digits in the number, both to
left and right of the decimal point.
• The decimal point isn’t counted in specifying the precision.
• Scale  Total number of digits to the right of the decimal point.
• Precision Range  1 to 38 Scale Range  -84 to 127.
Integer
• It is a whole number without any decimal part.
• Define a column with integer values, only the scale size is provided.
Fixed-point decimal number
• It has a specific number of digits to the right of the decimal point.
• The first number specifies precision and second number is the scale.
Floating-point decimal number
• It has a variable number of decimal places.
• It may appear after any number of digits in point, and it may not
appear at all.
• Define such a column, don’t specify the scale or precision along with
this data type.
• By defining a columns as a floating-point number, a value can be
stored in it with very high precision.
Date
• It is used for storing date and time values.
• Range  January 1, 4712 B.C and December 31, 9999 A.D.
• The day, month, century, hour, minute and second are stored in the
date type column.
• Default format  DD-MON-YY.
• DD – day of the month, MON – month’s first three letters (Capitalized)
and YY – last two digits of the year with three values are separated by
hyphens.
• DD-MON-YYYY format works default in Oracle9i and other format
required to use To_Date function.
• The default time format is HH:MM:SS: A.M., representing hours,
minutes and seconds in a 12-hour time format.
• If only a date is entered, the time defaults to 12:00:00 A.M.
• If only a time is entered, the date defaults to the first day of the
current month.
• Oracle9i provides users with quite a few built-in date functions for
date manipulation.
• Simple date arithmetic is enough to calculate age from the birth date!
The birth date never changes, so no maintenance on it is necessary.
Data Types Explanation
LONG It is used for variable-length character data up to 2 GB(Gigabytes) and only one long-type column in a table.
When defining to long-type, there is no need to specify its size.
NCHAR It is similar to Char but uses 2-byte binary encoding for each character. It uses 1-byte ASCII encoding for each
character, giving it the capability to represent 256 different characters.
This type is useful for character sets such as Japanese Kanji, which has thousands of different characters.
CLOB The Character Large Object data type is used to store single-byte character data up to 4 GB.
BLOB The Binary Large Object data type is used to store binary data up to 4 GB.
NCLOB The Character Large Object type uses 2-byte character codes.
BFILE The Binary File type stores references to a binary file that is external to the database and is maintained by the
operating system’s file system.
RAW(size) or
LONG(size)
These are used for raw binary data.
ROWID For unique row address in hexadecimal format
• Many of the Large Object (LOB) data types aren’t supported by all
versions of Oracle and its tools.
• These data types are used for storing digitized sounds, for images, or
to reference binary files from Microsoft Excel spreadsheets or
Microsoft Word documents.
Data Types Use
Varchar2 (size) Variable-length character data 1 to 4000 characters.
Char (size) Fixed-length character data 1 to 2000 characters.
Number (p) Integer values
Number (p, s) Fixed-point decimal values
Number Floating-point decimal values
DATE Date and time values
LONG Variable-length character data up to GB
NCHAR Similar to CHAR uses 2-byte encoding
CLOB Single-byte character data up to 4 GB
BLOB Binary data up to 4 GB
NCLOB Similar to CLOB; supports 2-byte encoding
BFILE Reference to an external binary file
RAW(size) or
LONG(size)
Raw binary data up to 2000 bytes
Same as RAW; stores up to 2 GB
ROWID Unique address of a row in a table.
Constraints
• It enforce rules on tables.
• An Oracle table can be created with the column names, data types
and column sizes, which are sufficient just to populate them with
actual data.
• Without constraints, no rules are enforced.
• It help to make our database one with integrity.
• The constraints are used in Oracle to implement integrity rules in
relational database.
• To implement data integrity at the individual-column level.
• Whenever a row/record is inserted, updated or deleted from the
table, a constraint must be satisfied for the operation to succeed.
• A table can’t be deleted if there are dependencies from other tables
in the form of foreign keys.
Types
• Integrity constraints  Define both the primary key and the foreign
key with the table and primary key it references.
• Value constraints  Define if NULL values are disallowed, if UNIQUE
values are required, and if only certain set of values are allowed in a
column.
Naming a constraint
• Oracle identifies constraints with an internal or user-created name.
• For a user’s account, each constraint name must be unique.
• A user can’t create constraints in two different tables with the same
name.
<table name>_<column name>_<constraint type>
• Table name  name of the table where the constraint is being
defined.
• Column name  name of the column to which the constraint applies.
• Constraint type  used to identify the constraint’s type.
Popular constraint abbreviation
Constraint Abbreviation
PRIMARY KEY Pk
FOREIGN KEY Fk
UNIQUE Uk
CHECK ck or cc
NOT NULL nn
Defining a constraint
• A constraint can be created at the same time the table is created, or it
can be added to the table afterward.
• There are two levels where a constraint is defined.
Column level
• It references a single column and is defined along with the definition
of the column.
• Any constraint can be defined at the column level except for a
FOREIGN KEY and composite primary key constraints.
Column datatype [CONSTRAINT constraint_name] constraint_type
Table level
• A table-level constraint references one or more columns and is
defined separately from the definitions of the columns.
• It is written after all columns are defined.
• All constraints can be defined at the table level except for the NOT
NULL constraint.
[CONSTRAINT constraint_name] constraint_type(Column….)
PRIMARY KEY CONSTRAINT
• It is also knows as the entity integrity constraint.
• It creates a primary key for the table.
• A table ca have only one primary key constraint.
• A column or combination of columns used as a primary key can’t have
a null value and it can only have unique values
ADBMS Unit-II b
FOREIGN KEY CONSTRAINT
• It is also known as the referential integrity constraint.
• It uses a column or columns as a foreign key, and it establishes a
relationship with the primary key of the same or another table.
• To establish a foreign key in a table, the other referenced table and its
primary key must already exists.
• Foreign key and referenced primary key columns need not have the same
name but a foreign key value must match the value in the parent table’s
primary key value or be NULL.
• Oracle doesn’t keep pointers for relationships, but they are based on
constraints and data values within those columns.
• The relationship is purely logical and is not physical in Oracle.
ADBMS Unit-II b
NOT NULL CONSTRAINT
• It ensures that the column has a value and the value is not a null
value.
• A space or a numeric zero is not a null value.
• There is no need to use the not null constraint for the primary key
column, because it automatically gets the not null constraint.
• The foreign key is permitted to have null values, but a foreign key is
sometimes given the not null constraint.
• The constraint can’t be entered at the table level.
UNIQUE CONSTRAINT
• It requires that every value in a column or set of columns be unique.
• If it is applied to a single column  value has unique, set of columns,
group of columns  has a unique value.
• It allows null values unless not null is alos applied to the column.
CHECK CONSTRAINT
• It defines a constraint that every row must satisfy.
• There are more than one Check constraint on a column and defined
column as well as table level.
NOT NULL CHECK CONSTRAINT
• It can be declared as a check constraint.
• It can be defined at column or table level.
DEFAULT VALUE (It’s not a constraint)
• It ensures that a particular column will always have a value when a
new row is inserted.
• It is used if a null value is inserted.

More Related Content

PDF
MySQL Indexing
PPTX
ADBMS DATATYPES
PPTX
Dynamic multi level indexing Using B-Trees And B+ Trees
PPTX
File Structures(Part 2)
PPTX
Indexing structure for files
PDF
Oracle sql in 7 days by suesh.n v 1.0
PDF
Indexing and-hashing
PPTX
Overview of Storage and Indexing ...
MySQL Indexing
ADBMS DATATYPES
Dynamic multi level indexing Using B-Trees And B+ Trees
File Structures(Part 2)
Indexing structure for files
Oracle sql in 7 days by suesh.n v 1.0
Indexing and-hashing
Overview of Storage and Indexing ...

What's hot (20)

PPTX
PPT
Indexing and Hashing
PPT
12. Indexing and Hashing in DBMS
PPT
File organization 1
PPTX
Indexing
PPT
Intro To TSQL - Unit 5
PDF
Database management system session 6
PPT
Indexing and hashing
PDF
Data and File Structure Lecture Notes
PPT
Indexing Data Structure
PDF
indexing and hashing
PPTX
Data storage and indexing
PPTX
Lec 1 indexing and hashing
PPTX
Adbms 22 dynamic multi level index using b and b+ tree
PPT
Intro to Data warehousing lecture 11
PPT
Intro to Data warehousing lecture 14
PPT
Intro to Data warehousing lecture 19
PPTX
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
PPT
Ardbms
Indexing and Hashing
12. Indexing and Hashing in DBMS
File organization 1
Indexing
Intro To TSQL - Unit 5
Database management system session 6
Indexing and hashing
Data and File Structure Lecture Notes
Indexing Data Structure
indexing and hashing
Data storage and indexing
Lec 1 indexing and hashing
Adbms 22 dynamic multi level index using b and b+ tree
Intro to Data warehousing lecture 11
Intro to Data warehousing lecture 14
Intro to Data warehousing lecture 19
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Ardbms
Ad

Similar to ADBMS Unit-II b (20)

PPT
Sql database object
PPT
Sql database object
PPT
Sql database object
PPT
Sql database object
PPT
Sql database object
PPT
Sql database object
PPT
Sql database object
DOCX
SQL, Oracle, Joins
PPTX
Sql fundamentals
PPT
DDL. data defination language for creating database
PPT
plsql Les09
PPT
Dbms oracle
PPT
PPTX
PPTX
429cf300-0dc7-4c2e-9280-d918d69e3cb4.pptx
PPTX
Oracle basic queries
PPTX
DDL(Data defination Language ) Using Oracle
PDF
DBMS MODULE 3 NOTES ENGINEERING CSE .pdf
PPTX
Sql database object
Sql database object
Sql database object
Sql database object
Sql database object
Sql database object
Sql database object
SQL, Oracle, Joins
Sql fundamentals
DDL. data defination language for creating database
plsql Les09
Dbms oracle
429cf300-0dc7-4c2e-9280-d918d69e3cb4.pptx
Oracle basic queries
DDL(Data defination Language ) Using Oracle
DBMS MODULE 3 NOTES ENGINEERING CSE .pdf
Ad

More from SSN College of Engineering, Kalavakkam (20)

PDF
Localization, Classification, and Evaluation.pdf
PPTX
Database Management System - 2a
PPTX
Database Management System
PPTX
Unit III - Inventory Problems
PPTX
PPTX
PPTX
PPTX
Unit IV-Project Management
PPTX
Web technology Unit-II Part-C
PPTX
Data structure Unit-I Part-C
PPTX
Data structure unit I part B
PPTX
Web technology Unit-II Part A
PPTX
Data structure Unit-I Part A
PPTX
Web technology Unit-I Part E

Recently uploaded (20)

PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Basic Mud Logging Guide for educational purpose
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Cell Types and Its function , kingdom of life
PPTX
master seminar digital applications in india
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Pre independence Education in Inndia.pdf
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
O7-L3 Supply Chain Operations - ICLT Program
Renaissance Architecture: A Journey from Faith to Humanism
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Basic Mud Logging Guide for educational purpose
VCE English Exam - Section C Student Revision Booklet
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Cell Types and Its function , kingdom of life
master seminar digital applications in india
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Cell Structure & Organelles in detailed.
Week 4 Term 3 Study Techniques revisited.pptx
TR - Agricultural Crops Production NC III.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Pre independence Education in Inndia.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf

ADBMS Unit-II b

  • 1. ADBMS Unit – II Data Definition Language (DDL)
  • 2. Naming Rules and Conventions • A table is an object that can store data in an Oracle database. • Create table  must specify table name, name of each column name with data type with size of each column name. • Oracle provides different constraints to specify a primary or a composite key for the table. • Define a foreign key in a table  references a primary key in another table. • To set data validation rules for each column and specify a column allows NULL values with unique values only.
  • 3. • Table and Column names  1 to 30 characters long  (A-Z,a-z,0-9, $, _ ,#). • Names are not case sensitive. • Oracle stores all object names in uppercase in its data dictionary and server- reserved word can’t be used. • Spaces and hyphens aren’t allowed.
  • 5. Data Types • When a table is created, each column in the table is assigned a data type. • It specifies the type of data that will be stored in that column. • It also help to optimize storage space.
  • 6. Varchar2 (Oracle9i) / Varchar (Latest) • It is a character data type to store variable-length alphanumeric data in a column. • VARCHAR is synonymous with VARCHAR2 but it could be a separate data type with different semantics in the future. • Maximum size  4000 characters in Oracle 9i • Minimum size  1 character. • The size is specified within parentheses.
  • 7. • If the data are smaller than the specified size, only the data value is stored and trailing spaces aren’t added to the value. • Spaces aren’t added to make its length equal to the size of the column. • If a value longer that the specified size is entered, however, an error is generated. • The longer values aren’t truncated.
  • 8. Char • It is a character data type to store fixed-length alphanumeric data in a column. • Maximum size  2000 characters (previous version  255 characters). • Minimum size  1 character. • If the value is smaller than the specified size, is entered, trailing spaces are added to make its length equal to the specified length. • If the value is longer than the specified size, an error occurs. • It is appropriate for fixed-length values.
  • 9. • The Char type uses the storage more efficiently and process data faster than the Varchar2 type. • In Oracle9i, the Char type can also take CHAR or BYTE parameters. • Each Char may take up 1 to 4 bytes. • Latest version not supported byte and char similiar character name updated in current version.
  • 10. Number • It is used to store negative, positive, integer, fixed-decimal and floating-point numbers. • It is used for any column names and its precision and scale can be specified. • Precision  Total number of significant digits in the number, both to left and right of the decimal point. • The decimal point isn’t counted in specifying the precision. • Scale  Total number of digits to the right of the decimal point. • Precision Range  1 to 38 Scale Range  -84 to 127.
  • 11. Integer • It is a whole number without any decimal part. • Define a column with integer values, only the scale size is provided.
  • 12. Fixed-point decimal number • It has a specific number of digits to the right of the decimal point. • The first number specifies precision and second number is the scale.
  • 13. Floating-point decimal number • It has a variable number of decimal places. • It may appear after any number of digits in point, and it may not appear at all. • Define such a column, don’t specify the scale or precision along with this data type. • By defining a columns as a floating-point number, a value can be stored in it with very high precision.
  • 14. Date • It is used for storing date and time values. • Range  January 1, 4712 B.C and December 31, 9999 A.D. • The day, month, century, hour, minute and second are stored in the date type column. • Default format  DD-MON-YY. • DD – day of the month, MON – month’s first three letters (Capitalized) and YY – last two digits of the year with three values are separated by hyphens. • DD-MON-YYYY format works default in Oracle9i and other format required to use To_Date function.
  • 15. • The default time format is HH:MM:SS: A.M., representing hours, minutes and seconds in a 12-hour time format. • If only a date is entered, the time defaults to 12:00:00 A.M. • If only a time is entered, the date defaults to the first day of the current month. • Oracle9i provides users with quite a few built-in date functions for date manipulation. • Simple date arithmetic is enough to calculate age from the birth date! The birth date never changes, so no maintenance on it is necessary.
  • 16. Data Types Explanation LONG It is used for variable-length character data up to 2 GB(Gigabytes) and only one long-type column in a table. When defining to long-type, there is no need to specify its size. NCHAR It is similar to Char but uses 2-byte binary encoding for each character. It uses 1-byte ASCII encoding for each character, giving it the capability to represent 256 different characters. This type is useful for character sets such as Japanese Kanji, which has thousands of different characters. CLOB The Character Large Object data type is used to store single-byte character data up to 4 GB. BLOB The Binary Large Object data type is used to store binary data up to 4 GB. NCLOB The Character Large Object type uses 2-byte character codes. BFILE The Binary File type stores references to a binary file that is external to the database and is maintained by the operating system’s file system. RAW(size) or LONG(size) These are used for raw binary data. ROWID For unique row address in hexadecimal format
  • 17. • Many of the Large Object (LOB) data types aren’t supported by all versions of Oracle and its tools. • These data types are used for storing digitized sounds, for images, or to reference binary files from Microsoft Excel spreadsheets or Microsoft Word documents.
  • 18. Data Types Use Varchar2 (size) Variable-length character data 1 to 4000 characters. Char (size) Fixed-length character data 1 to 2000 characters. Number (p) Integer values Number (p, s) Fixed-point decimal values Number Floating-point decimal values DATE Date and time values LONG Variable-length character data up to GB NCHAR Similar to CHAR uses 2-byte encoding CLOB Single-byte character data up to 4 GB BLOB Binary data up to 4 GB NCLOB Similar to CLOB; supports 2-byte encoding BFILE Reference to an external binary file RAW(size) or LONG(size) Raw binary data up to 2000 bytes Same as RAW; stores up to 2 GB ROWID Unique address of a row in a table.
  • 19. Constraints • It enforce rules on tables. • An Oracle table can be created with the column names, data types and column sizes, which are sufficient just to populate them with actual data. • Without constraints, no rules are enforced. • It help to make our database one with integrity. • The constraints are used in Oracle to implement integrity rules in relational database. • To implement data integrity at the individual-column level.
  • 20. • Whenever a row/record is inserted, updated or deleted from the table, a constraint must be satisfied for the operation to succeed. • A table can’t be deleted if there are dependencies from other tables in the form of foreign keys. Types • Integrity constraints  Define both the primary key and the foreign key with the table and primary key it references. • Value constraints  Define if NULL values are disallowed, if UNIQUE values are required, and if only certain set of values are allowed in a column.
  • 21. Naming a constraint • Oracle identifies constraints with an internal or user-created name. • For a user’s account, each constraint name must be unique. • A user can’t create constraints in two different tables with the same name. <table name>_<column name>_<constraint type> • Table name  name of the table where the constraint is being defined. • Column name  name of the column to which the constraint applies. • Constraint type  used to identify the constraint’s type.
  • 22. Popular constraint abbreviation Constraint Abbreviation PRIMARY KEY Pk FOREIGN KEY Fk UNIQUE Uk CHECK ck or cc NOT NULL nn
  • 23. Defining a constraint • A constraint can be created at the same time the table is created, or it can be added to the table afterward. • There are two levels where a constraint is defined. Column level • It references a single column and is defined along with the definition of the column. • Any constraint can be defined at the column level except for a FOREIGN KEY and composite primary key constraints. Column datatype [CONSTRAINT constraint_name] constraint_type
  • 24. Table level • A table-level constraint references one or more columns and is defined separately from the definitions of the columns. • It is written after all columns are defined. • All constraints can be defined at the table level except for the NOT NULL constraint. [CONSTRAINT constraint_name] constraint_type(Column….)
  • 25. PRIMARY KEY CONSTRAINT • It is also knows as the entity integrity constraint. • It creates a primary key for the table. • A table ca have only one primary key constraint. • A column or combination of columns used as a primary key can’t have a null value and it can only have unique values
  • 27. FOREIGN KEY CONSTRAINT • It is also known as the referential integrity constraint. • It uses a column or columns as a foreign key, and it establishes a relationship with the primary key of the same or another table. • To establish a foreign key in a table, the other referenced table and its primary key must already exists. • Foreign key and referenced primary key columns need not have the same name but a foreign key value must match the value in the parent table’s primary key value or be NULL. • Oracle doesn’t keep pointers for relationships, but they are based on constraints and data values within those columns. • The relationship is purely logical and is not physical in Oracle.
  • 29. NOT NULL CONSTRAINT • It ensures that the column has a value and the value is not a null value. • A space or a numeric zero is not a null value. • There is no need to use the not null constraint for the primary key column, because it automatically gets the not null constraint. • The foreign key is permitted to have null values, but a foreign key is sometimes given the not null constraint. • The constraint can’t be entered at the table level.
  • 30. UNIQUE CONSTRAINT • It requires that every value in a column or set of columns be unique. • If it is applied to a single column  value has unique, set of columns, group of columns  has a unique value. • It allows null values unless not null is alos applied to the column.
  • 31. CHECK CONSTRAINT • It defines a constraint that every row must satisfy. • There are more than one Check constraint on a column and defined column as well as table level.
  • 32. NOT NULL CHECK CONSTRAINT • It can be declared as a check constraint. • It can be defined at column or table level.
  • 33. DEFAULT VALUE (It’s not a constraint) • It ensures that a particular column will always have a value when a new row is inserted. • It is used if a null value is inserted.