SlideShare a Scribd company logo
1
Database SystemsDatabase Systems
Creating and Modifying
Database Objects
2
Database Objects
 An Oracle database consists of multiple
user accounts
 Each user account owns database
objects
 Tables
 Views
 Stored programs
 Etc.
3
 Query: command to perform
operation on database object
 Create
 Modify
 View
 Delete
 Structured Query Language (SQL)
 Standard query language for
relational databases
Database Queries
4
SQL Command Types
 Data Definition Language (DDL)
 Used to create and modify the structure of
database objects
 Data Manipulation Language (DML)
 Used to insert, update, delete, and view
database data
5
DDL Commands
 Used to create and modify the structure
of database objects
 CREATE
 ALTER
 DROP
 DDL commands execute as soon as
they are issued, and do not need to be
explicitly saved
6
DML Commands
 Used to insert, view, and modify database
data
 INSERT
 UPDATE
 DELETE
 SELECT
 DDL commands need to be explicitly saved or
rolled back
 COMMIT
 ROLLBACK
7
User Accounts
 Each Oracle database user has a user
schema
 Area in the database where the user’s
database objects are stored
 Identified by a unique username and
protected by a password
 Each user schema is granted specific
privileges
8
Types of Database Privileges
 System Privileges
 Control the operations that the user can perform
within the database

Connecting to the database, creating new tables,
shutting down the database, etc.
 Object Privileges
 Granted on individual database objects
 Controls operations that a user can perform on a
specific object (insert data, delete data, etc.)
 When you create an object in your user schema,
you can then grant object privileges on that object
to other database users
9
Oracle Naming Standard
 Oracle database objects must adhere to
the Oracle Naming Standard
 1 to 30 characters long
 Must begin with a character
 Can contain characters, numbers, and the
symbols $, _, and #
10
Creating New User Accounts
 Done by DBA
 Syntax:
CREATE username IDENTIFIED BY password;
11
Example Oracle System
Privileges
Privilege Leve
l
Purpose
CREATE SESSION User Connecting to database
CREATE TABLE User Creating tables in current user schema
DROP TABLE User Dropping tables in current user
schema
UNLIMITED
TABLESPACE
User Allows user to create schema objects
using as much space as needed
CREATE USER DBA Creating new users
GRANT ANY PRIVILEGE DBA Granting system privileges to users
CREATE ANY TABLE DBA Creating tables in any user schema
DROP ANY TABLE DBA Dropping tables in any user schema
12
Granting System Privileges
 Done by DBA
 Syntax:
GRANT privilege1, privilege2, … TO username;
13
Database Roles
 Role is a database object that can be
assigned system privileges
 Role is then assigned to a user, and the
user inherits the role’s privileges
 Used to easily assign groups of related
privileges to users
14
Creating Roles
 Syntax:
CREATE ROLE role_name;
15
Assigning Privileges to a Role
 Syntax:
GRANT privilege1, privilege2, …
TO role_name;
16
Assigning a Role to a User
 Syntax:
GRANT role_name TO user_name;
17
Revoking System Privileges
 Syntax:
REVOKE privilege1, privilege2, …
FROM username;
18
Administering System
Privileges
 To be able to grant system privileges to
other users, a user account must have
been granted the privilege WITH
ADMIN OPTION
19
 To create a table, you must
specify:
 Table name
 Field names
 Field data types
 Field sizes
 Constraints
Defining Database Tables
20
 Must follow the Oracle Naming
Standard
 Each table in a user schema must
have a unique name within that
user schema
 Each field in a table must have a
unique name within that table
Table and Field Names
21
 Data type: specifies type of data
stored in a field
 Date, character, number, etc.
 Uses
 Error checking
 Efficient use of storage space
Oracle Data Types
22
 VARCHAR2
 Variable-length character strings
 Maximum of 4,000 characters
 Must specify maximum width
allowed
 No trailing blank spaces are added
 Example declaration:
student_name VARCHAR2(30)
Oracle Character Data Types
23
 CHAR
 Fixed-length character data
 Maximum size 2000 characters
 Must specify maximum width allowed
 Adds trailing blank spaces to pad width
 Example declaration:
student_gender CHAR(1)
Character Data Types
24
 NCHAR
 Supports 16-digit binary character
codes
 Used for alternate alphabets
Character Data Types
25
 NUMBER
 stores values between 10-130
and 10126
 General declaration format:
variable_name NUMBER(precision, scale)
Number Data Type
26
 Number type (integer, fixed point,
floating point) specified by
precision and scale
 Precision: total number of digits on
either side of the decimal point
 Scale: number of digits to right of
decimal point
NUMBER Data Types
27
 Whole number with no digits to
right of decimal point
 Precision is maximum width
 Scale is omitted
 Sample declaration:
s_age NUMBER (2)
Integer Numbers
28
 Contain a specific number of
decimal places
 Precision is maximum width
 Scale is number of decimal places
 Sample declaration:
item_price NUMBER(5, 2)
Fixed Point Numbers
29
 Contain a variable number of
decimal places
 Precision and scale are omitted
 Sample declaration:
s_GPA NUMBER
Floating Point Numbers
30
 DATE
 Stores dates from 1/1/4712 BC to
12/31/4712 AD
 Stores both a date and time component
 Default date format:
DD-MON-YY HH:MI:SS AM
 example: 05-JUN-03 12:00:00 AM
 Sample declaration:
s_dob DATE
Date Date Type
31
 If no time value is given when a
new date is inserted, default value
is 12:00:00 AM
 If no date value is given when a
new time is inserted, default date
is first day of current month
Specifying Date and Time
Values
32
Large Object (LOB) Data
Types
 Binary Large Object (BLOB)
 Stores up to 4 GB of binary data
 Character Large Object (CLOB)
 Stores up to 4 GB of character data
 BFILE
 Stores a reference to a binary file maintained in
the operating system
 NCLOB
 Character LOB that supports 16-bit character code
33
Declaring LOB Data Fields
 Item size is not specified
 Examples:
item_image BLOB
item_image BFILE
34
 Syntax:
CREATE TABLE table_name
( fieldname1 datatype,
fieldname2 datatype, …);
 Example:
CREATE TABLE my_students
( s_id NUMBER(6),
s_name VARCHAR2(30),
s_dob DATE,
s_class CHAR(2));
Creating a Database Table
35
Constraints
 Rules that restrict the values that can
be inserted into a field
 Types of constraints
 Integrity: define primary and foreign keys
 Value: specify values or ranges of values
that can be inserted
36
Constraint Levels
 Table constraint
 Restricts the value of a field with respect to
all other table records
 Example: primary key value must be
unique for each record
 Column constraint
 Restricts values in a specific column
 Example: values in an S_GENDER field
must be ‘M’ or ‘F’
37
 Internal name used by DBMS to identify the
constraint
 Each constraint name in a user schema
must be unique
 If you do not name a constraint, the system
will automatically generate an unintuitive
name
Constraint Names
38
 Constraint naming convention:
tablename_fieldname_constraintID
 Constraint ID values:
 Primary key: pk
 Foreign key: fk
 Check condition: cc
 Not NULL: nn
 Unique: uk
 Example constraint name:
my_students_s_id_pk
Constraint Names
39
 Table-level
 Defining a primary key:
CONSTRAINT constraint_name PRIMARY KEY
 Example:
s_id NUMBER(6)
CONSTRAINT student_s_id_pk PRIMARY KEY
Primary Key Constraints
40
 Can be defined when field is declared
Primary Key Constraints
41
 Can also be defined after all table field
definitions are completed
Primary Key Constraints
42
 Syntax:
CONSTRAINT constraint_name
PRIMARY KEY (field1, field2)
 Must be defined after fields that compose
key are defined
Composite Primary Keys
43
 Table-level
 Can only be defined after field is defined as a
primary key in another table
 Syntax:
CONSTRAINT constraint_name
REFERENCES primary_key_table_name
(field_name)
Foreign Key Constraints
44
 Can be defined when field is declared
Foreign Key Constraints
45
 Can also be defined after all table field
definitions are completed
Foreign Key Constraints
46
 Column-level
 Restricts data values that can be inserted
in a field
 In general, avoid value constraints
because they make the database very
inflexible
Value Constraints
47
 Check condition: restricts to specific values
 Example: s_gender (M or F)
CONSTRAINT my_students_s_gender_cc
CHECK (s_gender = ‘M’) OR (s_gender = ‘F’)
 Not NULL: specifies that a field cannot be
NULL
 Example:
CONSTRAINT my_students_s_dob_nn
NOT NULL
Types of Value Constraints
48
 Default: specifies a default value that is inserted
automatically
 Example:
s_state CHAR(2) DEFAULT ‘WI’
 Unique
 Table constraint
 Specifies that a non-primary key field must have a unique
value
CONSTRAINT consultant_c_email_uk UNIQUE (c_email)
Types of Value Constraints
49
 Oracle SQL command line utility for
issuing SQL commands
 Starting SQL*Plus
SQL*Plus
50
 All commands must be terminated
with a semicolon
 Use a text editor and copy and
paste commands
 Character data is case sensitive
and must be in single quotes
‘M’
‘Sarah’
Using SQL*Plus
51
 Type exit at SQL> prompt
or
 Click Close button on SQL*Plus
window
Exiting SQL*Plus
52
 Ora.hlp file
 Oracle Technology Network
(OTN)
 http://otn.oracle.com
Oracle Help Resources
53
 Viewing a table’s structure
DESCRIBE table_name;
Viewing Table Information
54
Oracle Data Dictionary
 Contains tables that describe the database
structure
 Is in the SYSTEM user schema
 Is automatically updated as users create and
modify tables
 Cannot be updated directly
 Contains views that allow users to retrieve
information about the database structure
55
Data Dictionary Views
 Views present data in different formats
depending on the privileges of the user
 USER: shows all objects belonging to the
current user
 ALL: shows all objects belonging to the
current user, as well as objects current
user has privileges to manipulate
 DBA: allows users with DBA privileges to
view objects of all database users
56
Querying the Data Dictionary
Views
 Syntax:
SELECT field1, field2, …
FROM privilege_viewname;
57
Summary of Oracle
Data Dictionary Views
OBJECTS All database objects
TABLES Database tables
INDEXES Table indexes created to improve query
performance
VIEWS Database views
SEQUENCES Sequences created to automatically
generate surrogate key values
USERS Database users
CONSTRAINTS Table constraints
CONS_CONSTRAINT
S
Table columns that have constraints
IND_COLUMNS Indexed columns
TAB_COLUMNS All table columns
58
 Unrestricted actions
 Renaming tables
 Adding new columns
 Increasing column sizes
 Dropping columns
 Dropping constraints
Modifying Tables
59
 Restricted actions
 Dropping tables

Only allowed if table does not contain any fields that
are referenced as foreign keys, or if foreign key
constraints are dropped
 Changing a column’s data specification

Only allowed if existing data is compatible with new
data specification
 Decreasing column sizes

Only allowed if column does not contain any data
 Adding constraints

Only allowed if existing data meets requirements of
new constraint
Modifying Tables
60
Altering Tables
 Adding a new field:
ALTER TABLE tablename
ADD (fieldname field_specification);
61
Altering Tables
 Modifying an existing field:
ALTER TABLE tablename
MODIFY (fieldname new_field_specification);
62
Altering Tables
 Deleting an existing field:
ALTER TABLE tablename
DROP COLUMN fieldname;
63
Deleting Tables
 Syntax to delete table if no table fields
are referenced as foreign keys:
DROP TABLE tablename;
 Syntax to delete table and constraints if
table contains fields that are referenced
as foreign keys:
DROP TABLE tablename CASCADE CONSTRAINTS;

More Related Content

What's hot

introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
webhostingguy
 
Sql commands
Sql commandsSql commands
Sql commands
Pooja Dixit
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
NITISH KUMAR
 
NOSQL vs SQL
NOSQL vs SQLNOSQL vs SQL
NOSQL vs SQL
Mohammed Fazuluddin
 
Stored procedure
Stored procedureStored procedure
Nosql seminar
Nosql seminarNosql seminar
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
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
Punjab University
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
Md.Mojibul Hoque
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
1keydata
 
introduction to NOSQL Database
introduction to NOSQL Databaseintroduction to NOSQL Database
introduction to NOSQL Database
nehabsairam
 
Sql ppt
Sql pptSql ppt
Sql ppt
Anuja Lad
 
Graph databases
Graph databasesGraph databases
Graph databases
Vinoth Kannan
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
BG Java EE Course
 
Non relational databases-no sql
Non relational databases-no sqlNon relational databases-no sql
Non relational databases-no sql
Ram kumar
 
Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction
Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction
Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction
Mark Ginnebaugh
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Sachidananda M H
 

What's hot (20)

introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
Sql commands
Sql commandsSql commands
Sql commands
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
NOSQL vs SQL
NOSQL vs SQLNOSQL vs SQL
NOSQL vs SQL
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Nosql seminar
Nosql seminarNosql seminar
Nosql seminar
 
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
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
introduction to NOSQL Database
introduction to NOSQL Databaseintroduction to NOSQL Database
introduction to NOSQL Database
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Graph databases
Graph databasesGraph databases
Graph databases
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
Non relational databases-no sql
Non relational databases-no sqlNon relational databases-no sql
Non relational databases-no sql
 
Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction
Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction
Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 

Viewers also liked

Identifying rumours on Twitter
Identifying rumours on TwitterIdentifying rumours on Twitter
Identifying rumours on Twitter
Kim Holmberg
 
Les08 (manipulating data)
Les08 (manipulating data)Les08 (manipulating data)
Les08 (manipulating data)
Achmad Solichin
 
Basic Concept of Database
Basic Concept of DatabaseBasic Concept of Database
Basic Concept of Database
Marlon Jamera
 
09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP
Nguyen Tuan
 
Building a-database
Building a-databaseBuilding a-database
Building a-database
Harry Potter
 
Commands of DML in SQL
Commands of DML in SQLCommands of DML in SQL
Commands of DML in SQL
Ashish Gaurkhede
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Evaluation Datasets for Twitter Sentiment Analysis: A survey and a new datase...
Evaluation Datasets for Twitter Sentiment Analysis: A survey and a new datase...Evaluation Datasets for Twitter Sentiment Analysis: A survey and a new datase...
Evaluation Datasets for Twitter Sentiment Analysis: A survey and a new datase...
Knowledge Media Institute - The Open University
 
Database, data storage, hosting with Firebase
Database, data storage, hosting with FirebaseDatabase, data storage, hosting with Firebase
Database, data storage, hosting with Firebase
Tu Pham
 
Modern PHP Developer
Modern PHP DeveloperModern PHP Developer
Modern PHP Developer
Achmad Solichin
 
Database migration
Database migrationDatabase migration
Database migration
Sankar Patnaik
 
Rumor
RumorRumor
NoSQL Databases - Lecture 12 - Introduction to Databases (1007156ANR)
NoSQL Databases - Lecture 12 - Introduction to Databases (1007156ANR)NoSQL Databases - Lecture 12 - Introduction to Databases (1007156ANR)
NoSQL Databases - Lecture 12 - Introduction to Databases (1007156ANR)
Beat Signer
 
Database system concepts
Database system conceptsDatabase system concepts
Database system concepts
Kumar
 
Access2013 ch09
Access2013 ch09Access2013 ch09
Access2013 ch09
Kristin Harrison
 
MS Sql Server: Reporting manipulating data
MS Sql Server: Reporting manipulating dataMS Sql Server: Reporting manipulating data
MS Sql Server: Reporting manipulating data
DataminingTools Inc
 
Database management system
Database management systemDatabase management system
Database management system
RizwanHafeez
 
Sentiment Analysis in Twitter
Sentiment Analysis in TwitterSentiment Analysis in Twitter
Sentiment Analysis in Twitter
Ayushi Dalmia
 
Sentiment Analysis of Twitter Data
Sentiment Analysis of Twitter DataSentiment Analysis of Twitter Data
Sentiment Analysis of Twitter Data
Sumit Raj
 
Practical Object Oriented Models In Sql
Practical Object Oriented Models In SqlPractical Object Oriented Models In Sql
Practical Object Oriented Models In Sql
Karwin Software Solutions LLC
 

Viewers also liked (20)

Identifying rumours on Twitter
Identifying rumours on TwitterIdentifying rumours on Twitter
Identifying rumours on Twitter
 
Les08 (manipulating data)
Les08 (manipulating data)Les08 (manipulating data)
Les08 (manipulating data)
 
Basic Concept of Database
Basic Concept of DatabaseBasic Concept of Database
Basic Concept of Database
 
09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP
 
Building a-database
Building a-databaseBuilding a-database
Building a-database
 
Commands of DML in SQL
Commands of DML in SQLCommands of DML in SQL
Commands of DML in SQL
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 
Evaluation Datasets for Twitter Sentiment Analysis: A survey and a new datase...
Evaluation Datasets for Twitter Sentiment Analysis: A survey and a new datase...Evaluation Datasets for Twitter Sentiment Analysis: A survey and a new datase...
Evaluation Datasets for Twitter Sentiment Analysis: A survey and a new datase...
 
Database, data storage, hosting with Firebase
Database, data storage, hosting with FirebaseDatabase, data storage, hosting with Firebase
Database, data storage, hosting with Firebase
 
Modern PHP Developer
Modern PHP DeveloperModern PHP Developer
Modern PHP Developer
 
Database migration
Database migrationDatabase migration
Database migration
 
Rumor
RumorRumor
Rumor
 
NoSQL Databases - Lecture 12 - Introduction to Databases (1007156ANR)
NoSQL Databases - Lecture 12 - Introduction to Databases (1007156ANR)NoSQL Databases - Lecture 12 - Introduction to Databases (1007156ANR)
NoSQL Databases - Lecture 12 - Introduction to Databases (1007156ANR)
 
Database system concepts
Database system conceptsDatabase system concepts
Database system concepts
 
Access2013 ch09
Access2013 ch09Access2013 ch09
Access2013 ch09
 
MS Sql Server: Reporting manipulating data
MS Sql Server: Reporting manipulating dataMS Sql Server: Reporting manipulating data
MS Sql Server: Reporting manipulating data
 
Database management system
Database management systemDatabase management system
Database management system
 
Sentiment Analysis in Twitter
Sentiment Analysis in TwitterSentiment Analysis in Twitter
Sentiment Analysis in Twitter
 
Sentiment Analysis of Twitter Data
Sentiment Analysis of Twitter DataSentiment Analysis of Twitter Data
Sentiment Analysis of Twitter Data
 
Practical Object Oriented Models In Sql
Practical Object Oriented Models In SqlPractical Object Oriented Models In Sql
Practical Object Oriented Models In Sql
 

Similar to Sql database object

Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
VARSHAKUMARI49
 
DBMS Part-3.pptx
DBMS Part-3.pptxDBMS Part-3.pptx
DBMS Part-3.pptx
Prof. Dr. K. Adisesha
 
Lab
LabLab
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SakkaravarthiS1
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
SomeshwarMoholkar
 
12 SQL
12 SQL12 SQL
12 SQL
12 SQL12 SQL
chapter-14-sql-commands.pdf
chapter-14-sql-commands.pdfchapter-14-sql-commands.pdf
chapter-14-sql-commands.pdf
study material
 
Ankit
AnkitAnkit
Module 3
Module 3Module 3
Module 3
cs19club
 
6_SQL.pdf
6_SQL.pdf6_SQL.pdf
6_SQL.pdf
LPhct2
 
Database
Database Database
SQL2.pptx
SQL2.pptxSQL2.pptx
SQL2.pptx
RareDeath
 
DBMS MODULE 3 NOTES ENGINEERING CSE .pdf
DBMS MODULE 3 NOTES ENGINEERING CSE .pdfDBMS MODULE 3 NOTES ENGINEERING CSE .pdf
DBMS MODULE 3 NOTES ENGINEERING CSE .pdf
raki082m
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)
Achmad Solichin
 
Database Management Lab -SQL Queries
Database Management Lab -SQL Queries Database Management Lab -SQL Queries
Database Management Lab -SQL Queries
shamim hossain
 
Les09
Les09Les09
sql-commands.pdf
sql-commands.pdfsql-commands.pdf
sql-commands.pdf
Prof. Dr. K. Adisesha
 
Sql commands
Sql commandsSql commands
Sql commands
Prof. Dr. K. Adisesha
 
Sql commands
Sql commandsSql commands
Sql commands
Prof. Dr. K. Adisesha
 

Similar to Sql database object (20)

Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 
DBMS Part-3.pptx
DBMS Part-3.pptxDBMS Part-3.pptx
DBMS Part-3.pptx
 
Lab
LabLab
Lab
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
 
12 SQL
12 SQL12 SQL
12 SQL
 
12 SQL
12 SQL12 SQL
12 SQL
 
chapter-14-sql-commands.pdf
chapter-14-sql-commands.pdfchapter-14-sql-commands.pdf
chapter-14-sql-commands.pdf
 
Ankit
AnkitAnkit
Ankit
 
Module 3
Module 3Module 3
Module 3
 
6_SQL.pdf
6_SQL.pdf6_SQL.pdf
6_SQL.pdf
 
Database
Database Database
Database
 
SQL2.pptx
SQL2.pptxSQL2.pptx
SQL2.pptx
 
DBMS MODULE 3 NOTES ENGINEERING CSE .pdf
DBMS MODULE 3 NOTES ENGINEERING CSE .pdfDBMS MODULE 3 NOTES ENGINEERING CSE .pdf
DBMS MODULE 3 NOTES ENGINEERING CSE .pdf
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)
 
Database Management Lab -SQL Queries
Database Management Lab -SQL Queries Database Management Lab -SQL Queries
Database Management Lab -SQL Queries
 
Les09
Les09Les09
Les09
 
sql-commands.pdf
sql-commands.pdfsql-commands.pdf
sql-commands.pdf
 
Sql commands
Sql commandsSql commands
Sql commands
 
Sql commands
Sql commandsSql commands
Sql commands
 

More from Harry Potter

How to build a rest api.pptx
How to build a rest api.pptxHow to build a rest api.pptx
How to build a rest api.pptx
Harry Potter
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data mining
Harry Potter
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data mining
Harry Potter
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discovery
Harry Potter
 
Cache recap
Cache recapCache recap
Cache recap
Harry Potter
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherence
Harry Potter
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching works
Harry Potter
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
Harry Potter
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
Harry Potter
 
Smm & caching
Smm & cachingSmm & caching
Smm & caching
Harry Potter
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Harry Potter
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
Harry Potter
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
Harry Potter
 
Object model
Object modelObject model
Object model
Harry Potter
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
Harry Potter
 
Encapsulation anonymous class
Encapsulation anonymous classEncapsulation anonymous class
Encapsulation anonymous class
Harry Potter
 
Abstract class
Abstract classAbstract class
Abstract class
Harry Potter
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
Harry Potter
 
Api crash
Api crashApi crash
Api crash
Harry Potter
 
Rest api to integrate with your site
Rest api to integrate with your siteRest api to integrate with your site
Rest api to integrate with your site
Harry Potter
 

More from Harry Potter (20)

How to build a rest api.pptx
How to build a rest api.pptxHow to build a rest api.pptx
How to build a rest api.pptx
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data mining
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data mining
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discovery
 
Cache recap
Cache recapCache recap
Cache recap
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherence
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching works
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
 
Smm & caching
Smm & cachingSmm & caching
Smm & caching
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
Object model
Object modelObject model
Object model
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
 
Encapsulation anonymous class
Encapsulation anonymous classEncapsulation anonymous class
Encapsulation anonymous class
 
Abstract class
Abstract classAbstract class
Abstract class
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Api crash
Api crashApi crash
Api crash
 
Rest api to integrate with your site
Rest api to integrate with your siteRest api to integrate with your site
Rest api to integrate with your site
 

Recently uploaded

Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
GDSC PJATK
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Jeffrey Haguewood
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 

Recently uploaded (20)

Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 

Sql database object

  • 1. 1 Database SystemsDatabase Systems Creating and Modifying Database Objects
  • 2. 2 Database Objects  An Oracle database consists of multiple user accounts  Each user account owns database objects  Tables  Views  Stored programs  Etc.
  • 3. 3  Query: command to perform operation on database object  Create  Modify  View  Delete  Structured Query Language (SQL)  Standard query language for relational databases Database Queries
  • 4. 4 SQL Command Types  Data Definition Language (DDL)  Used to create and modify the structure of database objects  Data Manipulation Language (DML)  Used to insert, update, delete, and view database data
  • 5. 5 DDL Commands  Used to create and modify the structure of database objects  CREATE  ALTER  DROP  DDL commands execute as soon as they are issued, and do not need to be explicitly saved
  • 6. 6 DML Commands  Used to insert, view, and modify database data  INSERT  UPDATE  DELETE  SELECT  DDL commands need to be explicitly saved or rolled back  COMMIT  ROLLBACK
  • 7. 7 User Accounts  Each Oracle database user has a user schema  Area in the database where the user’s database objects are stored  Identified by a unique username and protected by a password  Each user schema is granted specific privileges
  • 8. 8 Types of Database Privileges  System Privileges  Control the operations that the user can perform within the database  Connecting to the database, creating new tables, shutting down the database, etc.  Object Privileges  Granted on individual database objects  Controls operations that a user can perform on a specific object (insert data, delete data, etc.)  When you create an object in your user schema, you can then grant object privileges on that object to other database users
  • 9. 9 Oracle Naming Standard  Oracle database objects must adhere to the Oracle Naming Standard  1 to 30 characters long  Must begin with a character  Can contain characters, numbers, and the symbols $, _, and #
  • 10. 10 Creating New User Accounts  Done by DBA  Syntax: CREATE username IDENTIFIED BY password;
  • 11. 11 Example Oracle System Privileges Privilege Leve l Purpose CREATE SESSION User Connecting to database CREATE TABLE User Creating tables in current user schema DROP TABLE User Dropping tables in current user schema UNLIMITED TABLESPACE User Allows user to create schema objects using as much space as needed CREATE USER DBA Creating new users GRANT ANY PRIVILEGE DBA Granting system privileges to users CREATE ANY TABLE DBA Creating tables in any user schema DROP ANY TABLE DBA Dropping tables in any user schema
  • 12. 12 Granting System Privileges  Done by DBA  Syntax: GRANT privilege1, privilege2, … TO username;
  • 13. 13 Database Roles  Role is a database object that can be assigned system privileges  Role is then assigned to a user, and the user inherits the role’s privileges  Used to easily assign groups of related privileges to users
  • 15. 15 Assigning Privileges to a Role  Syntax: GRANT privilege1, privilege2, … TO role_name;
  • 16. 16 Assigning a Role to a User  Syntax: GRANT role_name TO user_name;
  • 17. 17 Revoking System Privileges  Syntax: REVOKE privilege1, privilege2, … FROM username;
  • 18. 18 Administering System Privileges  To be able to grant system privileges to other users, a user account must have been granted the privilege WITH ADMIN OPTION
  • 19. 19  To create a table, you must specify:  Table name  Field names  Field data types  Field sizes  Constraints Defining Database Tables
  • 20. 20  Must follow the Oracle Naming Standard  Each table in a user schema must have a unique name within that user schema  Each field in a table must have a unique name within that table Table and Field Names
  • 21. 21  Data type: specifies type of data stored in a field  Date, character, number, etc.  Uses  Error checking  Efficient use of storage space Oracle Data Types
  • 22. 22  VARCHAR2  Variable-length character strings  Maximum of 4,000 characters  Must specify maximum width allowed  No trailing blank spaces are added  Example declaration: student_name VARCHAR2(30) Oracle Character Data Types
  • 23. 23  CHAR  Fixed-length character data  Maximum size 2000 characters  Must specify maximum width allowed  Adds trailing blank spaces to pad width  Example declaration: student_gender CHAR(1) Character Data Types
  • 24. 24  NCHAR  Supports 16-digit binary character codes  Used for alternate alphabets Character Data Types
  • 25. 25  NUMBER  stores values between 10-130 and 10126  General declaration format: variable_name NUMBER(precision, scale) Number Data Type
  • 26. 26  Number type (integer, fixed point, floating point) specified by precision and scale  Precision: total number of digits on either side of the decimal point  Scale: number of digits to right of decimal point NUMBER Data Types
  • 27. 27  Whole number with no digits to right of decimal point  Precision is maximum width  Scale is omitted  Sample declaration: s_age NUMBER (2) Integer Numbers
  • 28. 28  Contain a specific number of decimal places  Precision is maximum width  Scale is number of decimal places  Sample declaration: item_price NUMBER(5, 2) Fixed Point Numbers
  • 29. 29  Contain a variable number of decimal places  Precision and scale are omitted  Sample declaration: s_GPA NUMBER Floating Point Numbers
  • 30. 30  DATE  Stores dates from 1/1/4712 BC to 12/31/4712 AD  Stores both a date and time component  Default date format: DD-MON-YY HH:MI:SS AM  example: 05-JUN-03 12:00:00 AM  Sample declaration: s_dob DATE Date Date Type
  • 31. 31  If no time value is given when a new date is inserted, default value is 12:00:00 AM  If no date value is given when a new time is inserted, default date is first day of current month Specifying Date and Time Values
  • 32. 32 Large Object (LOB) Data Types  Binary Large Object (BLOB)  Stores up to 4 GB of binary data  Character Large Object (CLOB)  Stores up to 4 GB of character data  BFILE  Stores a reference to a binary file maintained in the operating system  NCLOB  Character LOB that supports 16-bit character code
  • 33. 33 Declaring LOB Data Fields  Item size is not specified  Examples: item_image BLOB item_image BFILE
  • 34. 34  Syntax: CREATE TABLE table_name ( fieldname1 datatype, fieldname2 datatype, …);  Example: CREATE TABLE my_students ( s_id NUMBER(6), s_name VARCHAR2(30), s_dob DATE, s_class CHAR(2)); Creating a Database Table
  • 35. 35 Constraints  Rules that restrict the values that can be inserted into a field  Types of constraints  Integrity: define primary and foreign keys  Value: specify values or ranges of values that can be inserted
  • 36. 36 Constraint Levels  Table constraint  Restricts the value of a field with respect to all other table records  Example: primary key value must be unique for each record  Column constraint  Restricts values in a specific column  Example: values in an S_GENDER field must be ‘M’ or ‘F’
  • 37. 37  Internal name used by DBMS to identify the constraint  Each constraint name in a user schema must be unique  If you do not name a constraint, the system will automatically generate an unintuitive name Constraint Names
  • 38. 38  Constraint naming convention: tablename_fieldname_constraintID  Constraint ID values:  Primary key: pk  Foreign key: fk  Check condition: cc  Not NULL: nn  Unique: uk  Example constraint name: my_students_s_id_pk Constraint Names
  • 39. 39  Table-level  Defining a primary key: CONSTRAINT constraint_name PRIMARY KEY  Example: s_id NUMBER(6) CONSTRAINT student_s_id_pk PRIMARY KEY Primary Key Constraints
  • 40. 40  Can be defined when field is declared Primary Key Constraints
  • 41. 41  Can also be defined after all table field definitions are completed Primary Key Constraints
  • 42. 42  Syntax: CONSTRAINT constraint_name PRIMARY KEY (field1, field2)  Must be defined after fields that compose key are defined Composite Primary Keys
  • 43. 43  Table-level  Can only be defined after field is defined as a primary key in another table  Syntax: CONSTRAINT constraint_name REFERENCES primary_key_table_name (field_name) Foreign Key Constraints
  • 44. 44  Can be defined when field is declared Foreign Key Constraints
  • 45. 45  Can also be defined after all table field definitions are completed Foreign Key Constraints
  • 46. 46  Column-level  Restricts data values that can be inserted in a field  In general, avoid value constraints because they make the database very inflexible Value Constraints
  • 47. 47  Check condition: restricts to specific values  Example: s_gender (M or F) CONSTRAINT my_students_s_gender_cc CHECK (s_gender = ‘M’) OR (s_gender = ‘F’)  Not NULL: specifies that a field cannot be NULL  Example: CONSTRAINT my_students_s_dob_nn NOT NULL Types of Value Constraints
  • 48. 48  Default: specifies a default value that is inserted automatically  Example: s_state CHAR(2) DEFAULT ‘WI’  Unique  Table constraint  Specifies that a non-primary key field must have a unique value CONSTRAINT consultant_c_email_uk UNIQUE (c_email) Types of Value Constraints
  • 49. 49  Oracle SQL command line utility for issuing SQL commands  Starting SQL*Plus SQL*Plus
  • 50. 50  All commands must be terminated with a semicolon  Use a text editor and copy and paste commands  Character data is case sensitive and must be in single quotes ‘M’ ‘Sarah’ Using SQL*Plus
  • 51. 51  Type exit at SQL> prompt or  Click Close button on SQL*Plus window Exiting SQL*Plus
  • 52. 52  Ora.hlp file  Oracle Technology Network (OTN)  http://otn.oracle.com Oracle Help Resources
  • 53. 53  Viewing a table’s structure DESCRIBE table_name; Viewing Table Information
  • 54. 54 Oracle Data Dictionary  Contains tables that describe the database structure  Is in the SYSTEM user schema  Is automatically updated as users create and modify tables  Cannot be updated directly  Contains views that allow users to retrieve information about the database structure
  • 55. 55 Data Dictionary Views  Views present data in different formats depending on the privileges of the user  USER: shows all objects belonging to the current user  ALL: shows all objects belonging to the current user, as well as objects current user has privileges to manipulate  DBA: allows users with DBA privileges to view objects of all database users
  • 56. 56 Querying the Data Dictionary Views  Syntax: SELECT field1, field2, … FROM privilege_viewname;
  • 57. 57 Summary of Oracle Data Dictionary Views OBJECTS All database objects TABLES Database tables INDEXES Table indexes created to improve query performance VIEWS Database views SEQUENCES Sequences created to automatically generate surrogate key values USERS Database users CONSTRAINTS Table constraints CONS_CONSTRAINT S Table columns that have constraints IND_COLUMNS Indexed columns TAB_COLUMNS All table columns
  • 58. 58  Unrestricted actions  Renaming tables  Adding new columns  Increasing column sizes  Dropping columns  Dropping constraints Modifying Tables
  • 59. 59  Restricted actions  Dropping tables  Only allowed if table does not contain any fields that are referenced as foreign keys, or if foreign key constraints are dropped  Changing a column’s data specification  Only allowed if existing data is compatible with new data specification  Decreasing column sizes  Only allowed if column does not contain any data  Adding constraints  Only allowed if existing data meets requirements of new constraint Modifying Tables
  • 60. 60 Altering Tables  Adding a new field: ALTER TABLE tablename ADD (fieldname field_specification);
  • 61. 61 Altering Tables  Modifying an existing field: ALTER TABLE tablename MODIFY (fieldname new_field_specification);
  • 62. 62 Altering Tables  Deleting an existing field: ALTER TABLE tablename DROP COLUMN fieldname;
  • 63. 63 Deleting Tables  Syntax to delete table if no table fields are referenced as foreign keys: DROP TABLE tablename;  Syntax to delete table and constraints if table contains fields that are referenced as foreign keys: DROP TABLE tablename CASCADE CONSTRAINTS;