Presentation 01
Presentation 01
Objects
Database Administration
Group no 01:
Nisha BSF2103259
Mahnoor BSF2204712
Tehmina Kausar BSF2204743
Hafsa Tabassum BSF2204726
Arfa Rehman BSF2204742
01
Create and modify
table, users, user
account
________________________
___
NISHA.
Why create table in DBA?
In RDBMS, Database tables are used to store the data in the form of
some structures (fields and records)
The CREATE TABLE command lets you define both column and table constraints,
while most other commands (like ALTER TABLE ) only let you work with table
constraints or NOT NULL . (You can also add column constraints when defining a
new column in an existing table.)
User
A Database User is defined as a person who interacts with data daily, updating,
reading, and modifying the given data.Database user accounts are used to
access and administer the database server.
User And user Account DB
Database Schema
Entire system that stores data and A collection of objects under a
objects. specific user.
A database can have multiple A schema contains objects like
schemas. tables, views, and procedures.
Physical structure includes data Logical structure that organizes
files and control files. objects.
Managed by DBA (Database
Managed by users or DBA.
Administrator).
Example: A company’s database Example: HR schema contains
containing HR and Sales schemas. employees and departments tables.
Objects inside a Schema:
01 02 03
Granting
Viewing Schemas and
Permissions
Creating a User (Schema): Users:
CREATE USER hr IDENTIFIED BY GRANT CONNECT, SELECT username
RESOURCE TO hr; FROM dba_users;
password;
04 05
Listing Objects in a
Schema: Dropping a User/Schema:
SELECT object_name, object_type DROP USER hr CASCADE;
FROM all_objects WHERE owner =
'HR';
COMMON SCHEMA OBJECTS
IN ORACLE
1- Tables
Store structured data in rows and
columns.
Example: Employee details, product inventories,
etc.
2-Views
A virtual table created by a query. It does not
store
data itself but displays data from one or more
tables.
3- Indexes
Improve the performance of data retrieval.
They are like pointers to specific rows in a table,
speeding up queries..
4-Sequences
Generate unique numbers automatically,
often used
to create primary key values.
5-Triggers
Automatically execute code when certain
events occur (like INSERT, UPDATE, or DELETE
operations).
Create the Procedure:
Procedure:
This procedure will increase an employee’s
salary by a given amount.
Explanation:
This procedure takes two
parameters:
p_emp_id: The ID of the
employee.
p_amount: The salary increase. Execute the Procedure:
It updates the employees table
by adding the specified amount
to the employee's salary.
Function Example in Oracle
This function will calculate the total
salary of all employees.
Explanation:
o The function calculates the sum of
all salaries from the employees
table.
o It returns the total salary as a
UseNUMBER.
the Function in a Query:
1. Oracle
2. Microsoft SQL Server
3. PostgreSQL
4. MySQL
5. IBM DB2
Data Types in Data Administration:
1. Integer (int): Whole numbers (e.g., 1, 2, 3). 1. Array: Collection of values (e.g., [1, 2, 3], ["a", "b",
"c"]).
2. Float (float): Decimal numbers (e.g., 3.14, -0.5).
2. Struct: Collection of key-value pairs (e.g., {name:
3. Character (char): Single characters (e.g., 'a', 'B'). "John", age: 30}).
4. String (varchar): Sequence of characters (e.g., 3. List: Ordered collection of values (e.g., [1, 2, 3], ["a",
"hello", "data administration"). "b", "c"]).
5. Boolean (bool): True or false values. 4. Dictionary (map): Unordered key-value pairs (e.g.,
6. Date (date): Calendar dates (e.g., 2022-07-25). {name: "John", age: 30}).
7. Time (time): Time values (e.g., 14:30:00). 5. Set: Unordered collection of unique values (e.g., {1,
2, 3}, {"a", "b", "c"}).
Spatial Data Types:Temporal Data Other Data Type:
Types:
1. Point: Geographic 1. Timestamp: Date and 1. Binary: Raw binary data
coordinates (e.g., latitude, time combined (e.g., (e.g., images, audio).
longitude). 2022-07-25 14:30:00).
2. JSON (JavaScript Object
2. LineString: Sequence of 2. Interval: Time duration Notation): Lightweight data
points (e.g., GPS tracks). (e.g., 1 hour, 30 minutes). interchange format.
3. Polygon: Closed shape 3. Period: Time range 3. XML (Extensible
defined by points (e.g., (e.g., 2022-01-01 to 2022- Markup Language):
country borders). 12-31). Markup language for data
4. Geometry: Combination of exchange.
points, lines, and polygons.
04
Creating table, manage
constraints,
_________________________
__
Hafsa.
Ways of Creating tables
Table Structure
1. Define clear and concise table names
1. Columns: Define data types and lengths
2. Use consistent naming conventions
2. Data types: INT, VARCHAR, DATE, TIME,
etc. 3. Define primary keys and foreign keys
3. Constraints: PRIMARY KEY, FOREIGN KEY, 4. Use indexes for frequent queries
UNIQUE, NOT NULL 5. Monitor table performance and adjust as needed
4. Indexes: Improve data retrieval
performance
Example
SQL Commands for Creating Tables
CREATE TABLE employees (
1. CREATE TABLE
id INT PRIMARY KEY,
2. ALTER TABLE
name VARCHAR(255),
3. DROP TABLE
age INT,
4. RENAME TABLE
department VARCHAR(100)
);
Here is the table representation of the employees table based on
your SQL code:
Creating tables:
Creating tables is a fundamental aspect of database
design and management. Tables store data in rows
and columns.
The CREATE TABLE statement is used to create a
new table in a database. Syntax: CREATE
TABLE table_name ( column1 datatype, column2
datatype, column3 datatype.
Types of Tables
1. Relational tables
2. NoSQL tables
3. Temporary tables
4. Partitioned tables
Managing Constraints:
Constraints ensure data integrity and
consistency in a database.
Types of Constraints
Departments Table
05
Create indexes, create
and use temporary
tables
_________________________
__
Arfa
What is Index?
An index is created on one or more columns of a table and functions like a book index,
allowing the database to find rows quickly without scanning the entire table.
Types of Indexes
1. Primary Index:
What It Is: Created automatically when you define
a primary key for a table.
Purpose: Ensures that each value in the primary
key column is unique and helps speed up searches.
2. Unique Index 3. Composite Index
What It Is: Ensures all values in the indexed column(s) are What It Is: An index on two or more columns in
unique but can be created on any column. a table.
Purpose: Prevents duplicate entries in the column. Purpose: Speeds up queries that filter using
multiple columns.
4. Full-Text Index
What It Is: An index that improves search capabilities on large text
fields.
Purpose: Allows complex searches like finding keywords within a body
of text.
What Are Temporary Tables?
Temporary tables are special types of tables that exist
only during the session or transaction they are created
in. When the session ends or the transaction is
committed, these tables are automatically dropped. This
ensures that no unnecessary data is stored permanently,
helping in conserving database resources.
There are two types of temporary tables:
Session Temporary Tables: These last for the duration
of the session and are dropped once the user
disconnects from the database.
Transaction Temporary Tables: These exist only
during a specific transaction and are dropped as soon as
the transaction is completed.
Using Temporary Tables in Schema Management
2.Testing Schema Changes
1.Data Migration Before applying changes to schema objects, DBAs can
use temporary tables to test the impact of those changes.
When migrating data from one schema to another, you can For instance, if you’re adding new columns or altering a
use temporary tables to hold data temporarily before table structure, you can replicate the permanent table as a
finalizing it into permanent tables. This helps in verifying temporary one to check for potential issues.
and transforming the data before committing it. Dropping Temporary Tables
Since temporary tables are dropped automatically at the
end of a session or transaction, DBAs do not have to
worry about manually removing them. However, if
needed, you can explicitly drop a temporary table:
Any Question?
Thanks!