0% found this document useful (0 votes)
21 views24 pages

DBMS

Uploaded by

ab0067752
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views24 pages

DBMS

Uploaded by

ab0067752
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

A

PRACTICAL FILE
OF
DATABASE MANAGEMENT SYSTEMS
SUBJECT CODE – BTCS-505-20

SESSION 2022 – 2026

SUBMITTED TO: SUBMITTED BY:


MR. AMANPARTAP SINGH RAMBABU
ASSISTANT PROFESSOR 227024
SCHOOL OF ENGI. BTECH – CSE
(AI&ML)
5 TH SEMESTER

APEEJAY INSTITUTE OF MANAGEMENT &


ENGINEERING TECHNICAL CAMPUS,
JALANDHAR
Task I: Basics of DBMS Packages (Oracle)

• Various RDBMS packages available in Market

227024 SIGNATURE
• Introduction to ORACLE and oraclelive.com compiler
• Features of ORACE and Roadmap of various Versions
• SQL Fundamentals
a. DDL
b. DML
c. DCL
d. TCL  Introduction to various Data Types.

RDBMS Database

A relational database management system (RDBMS) stores data in a tabular form where

a column represents a property and each row in a table represents a record. RDBMS

allows Create, Read, Update, and Delete (CRUD) operations. Structured Query

Language (SQL) is the language that is used to query, update, and delete data in

relational database management systems (RDBMS). SQL is a standard query language.

SQL language queries are also known as SQL commands or SQL statements.

Here is the list of the top 10 most popular RDBMSs are:

1. Oracle

2. MySQL

3. SQL Server

4. PostgreSQL

5. IBM DB2

6. Microsoft Access
7. SQLite

8. MariaDB
9. Informix

10. Azure SQL

227024 SIGNATURE
Oracle
Oracle Database is a relational database management system (RDBMS) developed by

Oracle Corporation. It is a software system that allows users to store, organize, and retrieve

large amounts of data efficiently and securely.

The Oracle Database is designed to run on various operating systems, including Windows,

Unix, and Linux. Businesses and organizations of all sizes use it for various applications,

such as e-commerce, customer relationship management, supply chain management, and

data warehousing.

Oracle Live SQL

Oracle Live SQL is a web-based SQL editor with an Oracle database built-in. It’s

maintained by Oracle and allows you to write and run SQL statements easily without

having to set up your own Oracle database.

As of October 2022, Oracle Live SQL runs Oracle database version 19c Enterprise Edition

19.14.0.0.0.

How to Access?

You can access Oracle Live SQL by going to livesql.oracle.com.

227024 SIGNATURE
You’ll see a page that looks like this:

The main feature of this page is to allow you to search or browse for tutorials. We’ll cover

this later in the guide, but Oracle Live SQL includes a range of tutorials to help you learn

specific features of Oracle, where you can read instructions and run the SQL right in the

browser.

We can also just access an SQL editor by clicking Start Coding Now.

However, you’ll need to be logged in to do this.

Once you’ve signed in, this is the main Oracle Live SQL screen you’ll see.

227024 SIGNATURE
There is a range of things on the screen:

Sidebar: On the left, you’ll see a sidebar that includes a few menu items such as Home,
My

Session, and Schema. We’ll cover these options later in this guide. If you don’t see this

sidebar, you can click on the hamburger menu to show and hide it.

SQL Worksheet: the top part of the main area of the screen is the SQL Worksheet. You

can write and run SQL statements here.

Output: the output of your SQL statements is shown at the bottom of the screen. This can

be resized up and down to make more room for the SQL or more room for the output.

Buttons: on the top right of the screen you can see a few buttons:

• Clear: clear the SQL in the worksheet

• Find: find a string in your SQL worksheet


• Actions: view session details, reset your session, or set the maximum rows

preference.

227024 SIGNATURE
• Save: save your SQL worksheet

• Run: run the script

We’ll learn more about these buttons later in the guide.

Footer: on the bottom of the screen, you can see some information about the tool: what

version of Oracle Live SQL is published, what Oracle database version it uses, and some

links to documentation and other tools.

Key features of Oracle Database are:

• Scalability: Oracle Database is designed to scale from small systems to large

enterprise deployments, providing support for multiple processors, storage systems,

and network configurations.

• High availability: The database has built-in mechanisms for data protection and

disaster recovery, including backup and recovery, replication, and clustering

technologies, which ensure that data is always available.

• Security: Oracle Database provides a variety of security features to protect data,

such as encryption, access controls, and auditing, ensuring that data is kept safe

from unauthorized access and tampering.

• Performance: The database is optimized for high performance, providing advanced

caching, indexing, and query optimization technologies, as well as support for in-

memory processing and parallel execution.

• Manageability: Oracle Database includes a range of tools and features for managing

the database, such as graphical user interfaces, command-line interfaces, and APIs,

which simplify tasks such as database monitoring, backup and recovery, and

performance tuning.

227024 SIGNATURE
• Compatibility: The database supports a wide range of programming languages and

interfaces, including SQL, PL/SQL, Java, and .NET, allowing developers to build

custom applications that can access and manipulate the data in the database.

• Cloud integration: Oracle Database provides native integration with cloud

platforms such as Oracle Cloud Infrastructure, enabling easy deployment and

management of databases in the cloud.

History of Oracle

Oracle Corporation was founded by Lawrence Ellison (Larry Ellison), Bob Miner, Ed

Oates, and Bruce Scott in August 1977. They have a lot of experience in building database

programs for several companies and builds their first project (a special database program)

for the CIA (Central Intelligence Agency). Oracle was named after "Project Oracle," a

project for one of their clients named Central Intelligence Agency, and the company that

created Oracle was called Systems Development Labs (SDL). Systems Development Labs

was renamed Relational Software Inc. (RSI) in 1978 to expand their market for the new

database. They had again changed the name of the company from RSI to Oracle Systems

Corporation in 1982.

The first commercially available RDBMS named Oracle V2 (Version 2) was built using
PDP-

11 assembler language (SQL-based RDBMS). Although they already developed a

commercial RDBMS in 1977, it wasn't available for purchase until 1979, when Oracle

version 2 was released.

In 1983, Oracle database portable version named "Oracle version 3" was released. This

version was written in the C programming language. It was the first relational database that

can run in mainframes, minicomputers, PCs, or any hardware with a C compiler. It also

supports SQL queries and transactions execution.

227024 SIGNATURE
The other subsequent versions are:

o In 1984, Oracle 4 was released that supports Transactions [Commit/Rollback],

export/import utilities, and the report writer.

o In 1985, Oracle 5 was released, which provides support for Client-Server


Architecture.

This new feature has the capability to connect the client's software to a database

server through a network.

o In 1989, Oracle 6 added support for PL/SQL language. It also comes with new

features such as OLTP high-speed systems, hot backup capability, and row-level

locking.

o In 1992, Oracle 7 was released. This version comes in the market as a result of four

years of hard work and two years of customer testing. It added some exciting

features and capabilities in the area of security, administration, development, and

performance. o In 1997, Oracle 8 was released. This version comes with the support

of ORDBMS that was designed to work with Oracle's network computer (NC). It

also added support for Java, HTML, and OLTP.

o In 1998, Oracle 8i was released. Here 'I' stands for Internet. It was the first database

version that added support for Web technologies such as Java and HTTP.

o In 2001, Oracle 9i was released with 400 new features such as XML, RAC (Real

Application Clusters), etc. These features reduce database size and provide high

availability & enhanced performance.

o In 2003, Oracle 10g was released with grid computing technology means grid. It

was the first version that supports 64-bit LINUX OS.

o In 2006, Oracle 11g was released. This version comes with new features such as

Oracle Database Replay, Transaction Management using Log Miner, Virtual

227024 SIGNATURE
Column Partitioning, Case sensitive passwords, Online Patching, Parallel Backups

on the same file using RMAN, and many others.

o In July 2014, Oracle 12C was released with Cloud support.

o In Feb 2018, Oracle 18 C was released. This version was the world's first

autonomous database.

Introduction to SQL

Structure Query Language(SQL) is a database query language used for storing and

managing data in Relational DBMS. SQL was the first commercial language introduced for

E.F Codd's Relational model of database. Today almost all RDBMS(MySql, Oracle,

Infomix, Sybase, MS Access) use SQL as the standard database query language. SQL is

used to perform all types of data operations in RDBMS.

SQL Command

SQL defines following ways to manipulate data stored in an RDBMS:

DDL: Data Definition Language

This includes changes to the structure of the table like creation of table, altering table,

deleting a table etc.

All DDL commands are auto-committed. That means it saves all the changes permanently

in the database.

Command Description

create to create new table or database

alter for alteration

227024 SIGNATURE
truncate delete data from table

drop to drop a table

rename to rename a table

DML: Data Manipulation Language

DML commands are used for manipulating the data stored in the table and not the table
itself.

DML commands are not auto-committed. It means changes are not permanent to database,

they can be rolled back.

Command Description

insert to insert a new row

update to update existing row

delete to delete a row

merge merging two rows or two tables

TCL: Transaction Control Language

These commands are to keep a check on other commands and their affect on the database.

These commands can annul changes made by other commands by rolling the data back to

its original state. It can also make any temporary change permanent.

Command Description

commit to permanently save

227024 SIGNATURE
rollback to undo change

savepoint to save temporarily

DCL: Data Control Language

Data control language are the commands to grant and take back authority from any

database user.

Command Description

grant grant permission of right

revoke take back permission.

Introduction to Oracle data types

In Oracle, every value has a data type that defines a set of characteristics for the value.

These characteristics cause Oracle to treat the values of one data type differently from the

values of another. For example, you can add values of the NUMBER data type, but not

values of the RAW data type.

When creating a new table, you specify a data type for each of its columns. Similarly, when
you create a new procedure, you specify a data type for each of its arguments.

The data type defines the allowed values that each column or argument can store. For

example, a DATE column cannot store a value of February 30, because this is not a valid

date.

Oracle has a number of built-in data types illustrated in the following table:

Cod Data Type


e

227024 SIGNATURE
1 VARCHAR2(size [BYTE | CHAR])

1 NVARCHAR2(size)

2 NUMBER[(precision [, scale]])

8 LONG

12 DATE

21 BINARY_FLOAT

22 BINARY_DOUBLE

23 RAW(size)

24 LONG RAW

69 ROWID

96 CHAR [(size [BYTE | CHAR])]

96 NCHAR[(size)]

112 CLOB

112 NCLOB

113 BLOB

114 BFILE

180 TIMESTAMP [(fractional_seconds)]

181 TIMESTAMP [(fractional_seconds)] WITH TIME ZONE

182 INTERVAL YEAR [(year_precision)] TO MONTH

183 INTERVAL DAY [(day_precision)] TO


SECOND[(fractional_seconds)]
208 UROWID [(size)]

227024 SIGNATURE
231 TIMESTAMP [(fractional_seconds)] WITH LOCAL TIMEZONE

Each data type has a code managed internally by Oracle. To find the data type code of a

value in a column, you use the DUMP() function.

Character data types

Character data types consist of CHAR, NCHAR, VARCHAR2, NVARCHAR2, and

VARCHAR.

The NCHAR and NVARCHAR2 data types are for storing Unicode character strings.

The fixed-length character data types are CHAR, NCHAR and the variable-length character

data types are VARCHAR2, NVARCHAR2.

VARCHAR is the synonym of VARCHAR2. However, you should not use VARCHAR

because Oracle may change its semantics in the future. For character data

types, you can specify their sizes either in bytes or characters.

Number data type

The NUMBER data type has precision p and scale s. The precision ranges from 1 to 38

while the scale range from -84 to 127.

If you don’t specify the precision, the column can store values including fixed-point and

floating-point numbers. The default value for the scale is zero.

Datetime and Interval data types

Datetime data types are DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE, and

TIMESTAMP WITH LOCAL TIME ZONE. The values of a datetime data type are

datetimes.

The interval data types are INTERVAL YEAR TO MONTH and INTERVAL DAY TO

227024 SIGNATURE
SECOND. The values of the interval data type are intervals.

RAW and LONG RAW data types

The RAW and LONG RAW data types are for storing binary data or byte strings e.g., the

content of documents, sound files, and video files.

The RAW data type can store up to 2000 bytes while the LONG RAW data type can store

up to 2GB.

A). Exercise on Creation of Table

I). Create the following table with mentioned constraints:


a). Relation Name: S

Column Data Type Width Constraints


Name

227024 SIGNATURE
Sno Varchar2 5 Primary Key
Sname Varchar2 20 Unique
City Varchar2 20 City must be New Delhi,
Patiala, Amritsar and Qadian
Status Number 3 Must be greater than 10

CODE:

CREATE TABLE S (
Sno VARCHAR2(5) PRIMARY KEY,
Sname VARCHAR2(20) UNIQUE,
City VARCHAR2(20) CHECK (City IN ('New Delhi', 'Patiala', 'Amritsar', 'Qadian')),
Status NUMBER(3) CHECK (Status > 10)
);
Explanation of the Code:
1. Sno VARCHAR2(5) PRIMARY KEY: Defines the Sno column as a VARCHAR2 type with
a maximum width of 5 characters and sets it as the primary key, which ensures that
the values in this column are unique and not null.
2. Sname VARCHAR2(20) UNIQUE: Defines the Sname column as a VARCHAR2 type
with a maximum width of 20 characters and adds a unique constraint to ensure that
all values in this column are distinct.
3. City VARCHAR2(20) CHECK (City IN ('New Delhi', 'Patiala', 'Amritsar', 'Qadian')):
Defines the City column as a VARCHAR2 type with a maximum width of 20 characters
and enforces a check constraint to ensure that the values in this column can only be
one of the specified cities: 'New Delhi', 'Patiala', 'Amritsar', or 'Qadian'.
4. Status NUMBER(3) CHECK (Status > 10): Defines the Status column as a NUMBER
type with a maximum of 3 digits and enforces a check constraint to ensure that the
values in this column are greater than 10.

OUTPUT:

227024 SIGNATURE
b). Relation Name: P

Column Data Width Constraints


Name Type
Pno Varchar2 5 Primary Key
Pnam Varchar2 20 Unique
e
Color Varchar2 20 Not Null
City Varchar2 20 City must be Jalandhar,
Patiala, Amritsar and Qadian

CODE:

CREATE TABLE P (
Pno VARCHAR2(5) PRIMARY KEY,
Pname VARCHAR2(20) UNIQUE,
Color VARCHAR2(20) NOT NULL,
City VARCHAR2(20) CHECK (City IN ('Jalandhar', 'Patiala', 'Amritsar', 'Qadian'))
);

Explanation of the SQL Code:

1. Pno VARCHAR2(5) PRIMARY KEY: Defines the Pno column as a VARCHAR2 type
with a maximum width of 5 characters and sets it as the primary key. This ensures that each
value in this column is unique and not null.
2. Pname VARCHAR2(20) UNIQUE: Defines the Pname column as a VARCHAR2 type
with a maximum width of 20 characters and adds a unique constraint to ensure that all values
in this column are distinct.
3. Color VARCHAR2(20) NOT NULL: Defines the Color column as a VARCHAR2 type
with a maximum width of 20 characters and adds a NOT NULL constraint, which ensures
that this column cannot have null values.
4. City VARCHAR2(20) CHECK (City IN ('Jalandhar', 'Patiala', 'Amritsar', 'Qadian')):
Defines the City column as a VARCHAR2 type with a maximum width of 20 characters and
enforces a check constraint to ensure that the values in this column can only be one of the
specified cities: 'Jalandhar', 'Patiala', 'Amritsar', or 'Qadian'.

OUTPUT:

227024 SIGNATURE
C). Relation Name: SP

Column Data Widt Constrains


Name Type h
Sno Varchar2 5 Refers Sno of Supplier table
Pno Varchar2 5 Refers Pno of Part table
Qty Numbe 4 Must be greater than 100
r

CODE:

CREATE TABLE SP (
Sno VARCHAR2(5),
Pno VARCHAR2(5),
Qty NUMBER(4),
PRIMARY KEY (Sno, Pno),
FOREIGN KEY (Sno) REFERENCES Supplier(Sno),
FOREIGN KEY (Pno) REFERENCES Part(Pno),
CHECK (Qty > 100)
);

Explanation of the SQL Code:

1. Sno VARCHAR2(5): Defines the Sno column as a VARCHAR2 type with a maximum width
of 5 characters. This column will reference the Sno column from the Supplier table.
2. Pno VARCHAR2(5): Defines the Pno column as a VARCHAR2 type with a maximum
width of 5 characters. This column will reference the Pno column from the Part table.

227024 SIGNATURE
3. Qty NUMBER(4): Defines the Qty column as a NUMBER type with up to 4 digits.
4. PRIMARY KEY (Sno, Pno): Defines a composite primary key on the combination of Sno
and Pno, ensuring that each pair of Sno and Pno is unique within the SP table.
5. FOREIGN KEY (Sno) REFERENCES Supplier(Sno): Establishes a foreign key constraint
on the Sno column, ensuring that every value in Sno exists in the Sno column of the Supplier
table.
6. FOREIGN KEY (Pno) REFERENCES Part(Pno): Establishes a foreign key constraint on
the Pno column, ensuring that every value in Pno exists in the Pno column of the Part table.
7. CHECK (Qty > 100): Enforces a check constraint on the Qty column to ensure that all values
are greater than 100.

OUTPUT:

II). Identify the primary key of SP table and apply Primary constraint on that.

 PRIMARY KEY (Sno, Pno): This line defines a composite primary key on the combination
of Sno and Pno. This ensures that the combination of these two columns is unique across all
rows in the SP table.
In this table:
 Sno and Pno together form the primary key, ensuring that each combination of these values is
unique in the SP table.
 The primary key constraint enforces uniqueness and helps in efficient data retrieval.
 Statement:
ALTER TABLE SP
ADD CONSTRAINT sp_pk
PRIMARY KEY (Sno, Pno);

B). Exercise on Insertion of records.

Insert the following record.


a). Relation Name: S

227024 SIGNATURE
SNO NAME CITY STATUS
S1 SUNEE QADIAN 20
T
S2 ANKIT AMRITSA 10
R
S3 AMIT PATIALA 30
CODE:

INSERT INTO S (Sno, Sname, City, Status)


VALUES ('S1', 'SUNEET', 'QADIAN', 20);
INSERT INTO S (Sno, Sname, City, Status)
VALUES ('S2', 'ANKIT', 'AMRITSAR', 10);
INSERT INTO S (Sno, Sname, City, Status)
VALUES ('S3', 'AMIT', 'PATIALA', 30);

Explanation:

 INSERT INTO S (Sno, Sname, City, Status): Specifies the table and columns into which
data will be inserted.
 VALUES ('S1', 'SUNEET', 'QADIAN', 20): Specifies the values to be inserted into the
columns Sno, Sname, City, and Status, respectively.

OUTPUT: SELECT * from S;

b). Relation Name: P

PNO NAME COLOR CITY

227024 SIGNATURE
P1 NUT RED QADIAN
P2 BOLT GREEN AMRITSAR
P3 SCREW BLUE JALANDHAR
P4 SCREW RED QADIAN

CODE:

INSERT INTO P (Pno, Pname, Color, City)


VALUES ('P1', 'NUT', 'RED', 'QADIAN');
INSERT INTO P (Pno, Pname, Color, City)
VALUES ('P2', 'BOLT', 'GREEN', 'AMRITSAR');
INSERT INTO P (Pno, Pname, Color, City)
VALUES ('P3', 'SCREW', 'BLUE', 'JALANDHAR');
INSERT INTO P (Pno, Pname, Color, City)
VALUES ('P4', 'SCREW', 'RED', 'QADIAN');

Explanation:

 INSERT INTO P (Pno, Pname, Color, City): Specifies the table P and the columns
into which data will be inserted.
 VALUES ('P1', 'NUT', 'RED', 'QADIAN'): Specifies the values for the columns Pno,
Pname, Color, and City, respectively.

OUTPUT: SELECT * from P;

c). Relation Name: SP

SNO PNO QTY


S1 P1 250

227024 SIGNATURE
S1 P2 300
S1 P3 500
S2 P1 250

CODE:

INSERT INTO SP (Sno, Pno, Qty)


VALUES ('S1', 'P1', 250);
INSERT INTO SP (Sno, Pno, Qty)
VALUES ('S1', 'P2', 300);
INSERT INTO SP (Sno, Pno, Qty)
VALUES ('S1', 'P3', 500);
INSERT INTO SP (Sno, Pno, Qty)
VALUES ('S2', 'P1', 250);

Explanation:

 INSERT INTO SP (Sno, Pno, Qty): Specifies the table SP and the columns into which data
will be inserted.
 VALUES ('S1', 'P1', 250): Specifies the values for the columns Sno, Pno, and Qty.

OUTPUT: SELECT * from SP;

b). Check the working of all the constraints by inserting the invalid data in the
corresponding columns.

1). TABLE S
i). Primary Key Violation:

227024 SIGNATURE
INSERT INTO S (Sno, Sname, City, Status)
VALUES ('S1', 'SUNEET', 'QADIAN', 20);
INSERT INTO S (Sno, Sname, City, Status)
VALUES ('S1', 'ANOTHER_NAME', 'QADIAN', 30); ----//Should fail due to duplicate Sno

ii). Unique Constraint Violation:

INSERT INTO S (Sno, Sname, City, Status)


VALUES ('S2', 'SAME_NAME', 'AMRITSAR', 15);
INSERT INTO S (Sno, Sname, City, Status)
VALUES ('S3', 'SAME_NAME', 'PATIALA', 25); ---//Should fail due to duplicate Sname

iii). Check Constraint Violation (City):

INSERT INTO S (Sno, Sname, City, Status)


VALUES ('S4', 'NEW_ENTRY', 'INVALID_CITY', 20); ---// Should fail due to invalid City

iv). Check Constraint Violation (Status):

INSERT INTO S (Sno, Sname, City, Status)


VALUES ('S5', 'NEW_ENTRY', 'NEW DELHI', 10); ---// Should fail due to Status <= 10

2). TABLE P

i). Primary Key Violation:


INSERT INTO P (Pno, Pname, Color, City)
VALUES ('P1', 'NUT', 'RED', 'QADIAN');
INSERT INTO P (Pno, Pname, Color, City)
VALUES ('P1', 'BOLT', 'GREEN', 'AMRITSAR'); ---// Should fail due to duplicate Pno

ii). Unique Constraint Violation:


INSERT INTO P (Pno, Pname, Color, City)
VALUES ('P2', 'SCREW', 'BLUE', 'JALANDHAR');
INSERT INTO P (Pno, Pname, Color, City)
VALUES ('P3', 'SCREW', 'RED', 'QADIAN'); ---//Should fail due to duplicate Pname

iii). Not Null Constraint Violation:


INSERT INTO P (Pno, Pname, Color, City) VALUES ('P4', 'NEW_PART', NULL, 'JALANDHAR');
-- Should fail due to NULL Color

iv). Check Constraint Violation (City):


INSERT INTO P (Pno, Pname, Color, City) VALUES ('P5', 'NEW_PART', 'BLACK',
'INVALID_CITY'); -- Should fail due to invalid City

3). TABLE SP

i). Primary Key Violation:


INSERT INTO SP (Sno, Pno, Qty)

227024 SIGNATURE
VALUES ('S1', 'P1', 250);
INSERT INTO SP (Sno, Pno, Qty)
VALUES ('S1', 'P1', 300); --// Should fail due to duplicate combination of Sno and Pno

ii). Foreign Key Constraint Violation (Sno):


INSERT INTO SP (Sno, Pno, Qty)
VALUES ('INVALID_SNO', 'P1', 250); ---//Should fail due to Sno not existing in Supplier
table

iii). Foreign Key Constraint Violation (Pno):


INSERT INTO SP (Sno, Pno, Qty)
VALUES ('S1', 'INVALID_PNO', 250); ---//Should fail due to Pno not existing in Part table

iv). Check Constraint Violation (Qty):


INSERT INTO SP (Sno, Pno, Qty)
VALUES ('S1', 'P1', 50); ---//Should fail due to Qty <= 100

Note down the errors encountered.

FOR TABLE S
Primary Key Violation:
Unique Constraint Violation:
Check Constraint Violation (City):
Check Constraint Violation (Status):

ERROR- ORA-00001: unique constraint (schema.constraint_name) violated

FOR TABLE P
Primary Key Violation:
Unique Constraint Violation:
Not Null Constraint Violation:
Check Constraint Violation (City):

ERROR- ORA-00001: unique constraint (schema.constraint_name) violated

FOR TABLE SP
Primary Key Violation:
Foreign Key Constraint Violation (Sno):
Foreign Key Constraint Violation (Pno):
Check Constraint Violation (Qty):

ERROR- - ORA-00001: unique constraint (schema.constraint_name) violated


3). Imposing Constraints at Table Level and Column Level with examples and screenshots

Column-Level Constraints
CREATE TABLE Employee (

227024 SIGNATURE
EmpID INT PRIMARY KEY -- Primary Key Constraint at column level
Name VARCHAR(100) NOT NULL, -- Not Null Constraint at column level
Email VARCHAR(100) UNIQUE, -- Unique Constraint at column level
Salary DECIMAL(10, 2) CHECK (Salary > 0) -- Check Constraint at column level
);
* Primary Key Constraint: Ensures EmployeeID is unique and not null.
* Not Null Constraint: Ensures Name cannot be null.
* Unique Constraint: Ensures Email is unique across the table.
* Check Constraint: Ensures Salary is greater than 0.

Table-Level Constraints
CREATE TABLE Order (
OrderID INT,
CustomerID INT,
ProductID INT,
Quantity INT,
PRIMARY KEY (OrderID), -- Primary Key Constraint at table level
FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID), -- Foreign Key
Constraint at table level
FOREIGN KEY (ProductID) REFERENCES Product(ProductID), -- Foreign Key
Constraint at table level
CHECK (Quantity > 0) -- Check Constraint at table level
);

* Primary Key Constraint: Ensures OrderID is unique across the table.


* Foreign Key Constraints: Ensure CustomerID and ProductID refer to valid entries in the
Customer and Product tables, respectively.
* Check Constraint: Ensures Quantity is greater than 0.

227024 SIGNATURE

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy