0% found this document useful (0 votes)
7 views37 pages

Presentation 01

The document provides an overview of database administration, focusing on managing schema objects, creating and modifying tables, and user accounts. It details the roles of schemas, the types of database objects, and important commands for schema management. Additionally, it covers indexing, temporary tables, and constraints to ensure data integrity within a database.

Uploaded by

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

Presentation 01

The document provides an overview of database administration, focusing on managing schema objects, creating and modifying tables, and user accounts. It details the roles of schemas, the types of database objects, and important commands for schema management. Additionally, it covers indexing, temporary tables, and constraints to ensure data integrity within a database.

Uploaded by

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

Managing Schema

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)

Create And modify


table
The SQL ALTER TABLE statement is used to modify the structure of an
existing table in a relational database. It allows you to add, modify, or delete
columns, as well as apply constraints, such as primary keys and foreign keys,
and make other structural changes to the table.
Create table:
To create a new database
in SQL we use the
CREATE DATABASE
command and then we
mention the name of the
database
Difference between create table or alter table

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

For users to access your


database, you the database
administrator must create
user accounts and grant
appropriate database access
privileges to those accounts.
A user account is identified
by a username and defines
the user’s security
attributes, including the
following: Authentication
method.
02
Schemas, and schema
objects, naming schema
objects
___________________________
Mahnoor.
SCHEMAS IN DBA:

A schema is a logical container containing objects like


tables, views, indexes, triggers, procedures, and
functions.

Each Oracle user has a schema with the same name as


the user. For example, a user named HR will have a
schema called HR.

In Oracle Database, schemas are collections of


database objects that belong to a specific user
1.Key Concepts for Schemas in DBA
2.Schemas vs. Databases:

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:

Tables Store data.

Indexes Speed up queries

Views Logical representations of tables or queries.

Automatic actions that happen when certain


Triggers
events occur.

Procedure Perform tasks but do not return a value.

functions Perform tasks and return a value.


DBA Responsibilities with
Schemas:
1. Creating Schemas:).
2. Granting Permissions
3. Managing Schema Objects
4. Monitoring Usage
Important DBA Commands for Schema Management

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:

Result: This will return the total salary from the


employees table.
NAMING SCHEMA OBJECTS IN
ORACLE
When creating schema objects (like tables, views, indexes, etc.), names must follow
certain conventions and rules to ensure the objects are valid and easy to manage

1. GENERAL NAMING RULES FOR SCHEMA OBJECTS


JUST NAMES
2.Best Practices for Naming Schema
Objects
3.DATABASE SCHEMAS ARE USED
FOR:
03
Object namespace and
data type
_________________________
__
Tahmina.
Object namespace?
●In computing, a namespace is a set of signs (names) that are used to
identify and refer to objects of various kinds.
● Object Storage namespace serves as the top-level container for all
buckets and objects.
●In a database, an object namespace refers to a logical grouping of
database objects, such as:
1. Tables
2. Views
3. Indexes
4. Sequences
5. Synonyms
Types of namespaces:

Schema Database System


A logical grouping The top-level
of database objects, Reserved for system-
namespace,
often associated containing all generated objects.
with a username. schemas and
objects.
Common namespace-related commands:
Benefits:
1. CREATE SCHEMA (create a new schema)
1. Improved organization
2. ALTER SCHEMA (modify an existing schema)
2. Reduced naming conflicts
3. DROP SCHEMA (delete a schema)
3. Enhanced security
4. GRANT (assign permissions to a schema or object)
4. Simplified object management
5. REVOKE (revoke permissions from a schema or
object)
Database management systems (DBMS) with
namespace support:

1. Oracle
2. Microsoft SQL Server
3. PostgreSQL
4. MySQL
5. IBM DB2
Data Types in Data Administration:

Primitive Data Types Complex Data Types:

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

1. Primary Key (PK) - Unique identifier for


each row.
2. Foreign Key (FK) - Links tables and
maintains referential integrity.
3. Unique (UQ) - Ensures unique values in a
column.
4. Not Null (NN) - Requires a value in a
column.
SQL Commands for Managing Constraints
1. CREATE TABLE with constraints.
2. ALTER TABLE to add/drop constraints.
3. DROP CONSTRAINT to remove constraints.
Employees Table

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!

You might also like