0% found this document useful (0 votes)
23 views23 pages

Database Administrator Roles & Views

Uploaded by

Samar Aftab
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)
23 views23 pages

Database Administrator Roles & Views

Uploaded by

Samar Aftab
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

Database Administration

By
Raheela Zaib
What is a database administrator (DBA)?
• A database administrator (DBA) is the information technician responsible for
directing and performing all activities related to maintaining and securing a
successful database environment.
• A DBA ensures an organization's databases and related applications operate
functionally and efficiently.
• DBAs frequently design and develop new features and debug issues, while
working alongside a diverse group of individuals such as developers, data
structure and business stakeholders. Therefore, they're expected to be proficient
in both technical and business skills.
What are the roles and responsibilities of a DBA?
• Database deployment and management: DBA keeps databases and applications
running up to performance, availability and recoverability standards while
handling additional functions.
• Documentation and training: The DBA must also establish policies and
procedures pertaining to the management, security, maintenance and use of the
database management system.
• Troubleshooting: When problems arise, the DBA is the focal point for resolution,
including troubleshooting, root cause analysis fine tuning and optimizing the
performance of tasks and programs that access the database.
• Backup and disaster recovery: The DBA is responsible for ensuring that databases
and data are backed up appropriately and can be recovered correctly and quickly
in the event of failure.
What are the roles and responsibilities of a DBA?
• Efficient database design: Database administrators work with application
developers to ensure accurate and efficient application design for database
access.
• Optimizing database performance: Database performance is the optimization of
resource usage to increase throughput and minimize contention, enabling the
largest possible workload to be processed.
• User access and support: A DBA creates new user accounts and provides access
permissions. They also create and manage database reports, visualizations and
dashboards to help users easily understand the status of their database.
What are the DCL commands in DBMS?
• Data control language (DCL) is used to access the stored data. It is mainly used
for revoke and to grant the user the required access to a database.
• It helps in controlling access to information stored in a database. It complements
the data manipulation language (DML) and the data definition language (DDL).
• It is the simplest among three commands.
• It provides the administrators, to remove and set database permissions to
desired users as needed.
• DDL Commands
1. Grant
2. Revoke
DCL Commands
• The Data Control Language (DDL) commands are as follows −
• GRANT Command
• It is employed to grant a privilege to a user. Grant command allows specified users to
perform specified tasks
• Syntax
GRANT privilege_name on objectname to user;
• Example: GRANT SELECT, UPDATE ON employees TO Ali.
• Here,
• privilege names are SELECT,UPDATE,DELETE,INSERT,ALTER,ALL
• objectname is table name
• user is the name of the user to whom we grant privileges
DDL Commands
• REVOKE Command
• It is employed to remove a privilege from a user. Revoke helps the owner to
cancel previously granted permissions.
• Syntax
REVOKE privilege_name on objectname from user;
• Example: REVOKE SELECT, UPDATE ON employees TO Ali.
• Flush Privileges:
• After revoking privileges, it's a good practice to flush the privileges to ensure that
the changes take effect:
FLUSH PRIVILEGES;
Views in Database
• view is a virtual table representing the result of a database query.
• View defines a customized query that retrieves data from one or more tables, and
represents the data as if it was coming from a single source.
• Views allow you to encapsulate complex queries, simplify data access, and
enhance security by restricting direct access to underlying tables.
• Create a view by selecting fields from one or more tables present in the database.
• A View can either have all the rows of a table or specific rows based on certain
conditions.
• It does not hold the actual data; it holds only the definition of the view in the
data dictionary.
Views in Database
• The view is a query stored in the data dictionary, on which the user can query just
like they do on tables.
• It does not use the physical memory, only the query is stored in the data
dictionary.
• It is computed dynamically, whenever the user performs any query on it. Changes
made at any point in view are reflected in the actual base table.
Views in Database
Key Features and Benefits of Views
[Link] Complex Queries:
1. Encapsulate complex joins, aggregations, and computations in a view,
allowing users to query the view instead of writing complex SQL.
[Link]:
1. Restrict access to sensitive data by creating views that expose only specific
columns or rows.
[Link] Abstraction:
1. Provide a level of abstraction over the physical schema, allowing changes to
the underlying schema without affecting dependent queries.
[Link]:
1. Promote reusability of SQL code by creating views that can be used in
multiple queries.
Types of Views
• Views in a database can be categorized into several types based on their
characteristics and usage. Here are the main types of views:
1. Simple Views
• Definition: Simple views are based on a single table and do not contain any of the
following: group functions, GROUP BY clauses, DISTINCT keyword, JOINs, or
subqueries.
• Example
CREATE VIEW simple_view AS
SELECT employee_id, first_name, last_name
FROM employees;
1. Simple Views
Types of Views
2. Complex Views
• Definition: Complex views can be based on multiple tables and can include
features such as JOINs, group functions, GROUP BY clauses, DISTINCT keyword,
and subqueries.
• Example
CREATE VIEW complex_view AS
SELECT e.employee_id, e.first_name, e.last_name, d.department_name,
SUM([Link]) as total_sales
FROM employees e
JOIN departments d ON e.department_id = d.department_id
JOIN orders o ON e.employee_id = o.employee_id
GROUP BY e.employee_id, e.first_name, e.last_name, d.department_name;
2. Complex Views
2. Complex Views
Types of Views
3. Materialized Views
• Definition: Materialized view replicates the retrieved data physically. This
replicated data can be reused without executing the view again. This type of view
is also known as "SNAPSHOTS". Materialized view reduce the processing time to
regenerate the whole data. It helps remote users to replicate data locally and
improve query performance. Materialized views mostly used in data warehouses.
• Example:
CREATE MATERIALIZED VIEW sales_summary AS
SELECT product_id, SUM(quantity) AS total_quantity, SUM(price) AS total_price
FROM order_items
GROUP BY product_id;
3. Materialized View
3. Materialized View
Creating Views
To create a view, you use the CREATE VIEW statement followed by the view name
and the SQL query that defines the view.
Syntax
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Example
CREATE VIEW active_employees AS
SELECT employee_id, first_name, last_name, department
FROM employees
WHERE active = TRUE;
Updating Views:
Use CREATE OR REPLACE VIEW to modify the view definition.
Syntax
•CREATE OR REPLACE VIEW active_employees AS
SELECT employee_id, first_name, last_name, department, hire_date
FROM employees
WHERE active = TRUE;

Dropping Views:
•Use DROP VIEW to remove a view.
Syntax
DROP VIEW active_employees;
Pros and Cons of Views
Pros
• It helps us to provide an abstraction to various users or hide the complexity for
users.
• It can help us to simplify complex queries into a simpler one.
• Views can be used for security purposes or can add extra value from the security
point of view
• It does not hold any space because it only has the definition in the data dictionary
Cons
• Performance cost and computation time.
• Base table structure dependency, change in table structure, then you have to
change the view definition associated with it.
The END

You might also like