0% found this document useful (0 votes)
21 views

Unit 1 - Week2-Text Learning

This document provides an overview of topics covered in Unit 1 - Week 2 of a database systems course, including data definition commands in SQL, database system architecture, an overview of SQL, data manipulation commands in SQL, and set operations. The key topics are explained in detail over multiple sections, covering concepts such as CREATE, DROP, ALTER, and TRUNCATE statements; database users and interfaces; the query processor; and UNION, UNION ALL, INTERSECT, and MINUS set operations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Unit 1 - Week2-Text Learning

This document provides an overview of topics covered in Unit 1 - Week 2 of a database systems course, including data definition commands in SQL, database system architecture, an overview of SQL, data manipulation commands in SQL, and set operations. The key topics are explained in detail over multiple sections, covering concepts such as CREATE, DROP, ALTER, and TRUNCATE statements; database users and interfaces; the query processor; and UNION, UNION ALL, INTERSECT, and MINUS set operations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Unit 1 – Week 2

Database Systems

Database Systems: SQL: Data definition Commands – Database System Architecture – Overview
of SQL – SQL: Data Manipulation commands – Set Operations.

Week 2
Learning Objectives:

1. Understand the commands of Data definition Language in SQL


2. Explain the Architecture of Database Systems.
3. Summarize the overview of SQL in DBMS.
4. Understand the Data manipulation commands in SQL.
5. Types of Set operations in DBMS

Key Topics
1.1 Data definition Commands

1.1.1 Create

1.1.2 Drop

1.1.3 Alter

1.1.4 Truncate
1.2 DBMS System Architecture
1.2.1 Database users and user interfaces
1.2.2 Database Administrator
1.3 Overview of SQL
1.3.1 Rules
1.3.2 Process of SQL
1.3.3 Characteristics of SQL
1.3.4 Advantages of SQL
1.3.5 Types of SQL
1.4 Data Manipulation commands
1.4.1 Insert
1.4.2 Update
1.4.3 Alter
1.5 Set Operations
1.5.1 Union

1|Page
1.5.2 Union All
1.5.3 Intersect
1.5.4 Minus

1.6 Summary

1.1 Data Definition Commands


Data Definition Language:
 DDL modifies the table's structure, such as by adding, deleting, or changing a table.
 All DDL commands are auto-committed, which means they store all database changes
permanently.

1.1.1 CREATE

• It is used to create a new table in the database.


Syntax:
• CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES [...]);
• Example:
• CREATE TABLE EMPLOYEE (Name VARCHAR2 (20), Email VARCHAR2
(100), DOB DATE);

1.1.2 DROP
This command can delete an index, table or view. Basically, any component from a relational
database management system can be removed using the Drop command. Once the object is dropped,
it cannot be reused.

The general syntax of drop command is as follows −


 DROP TABLE <table_name>;
 DROP DATABASE <database_name>;
 DROP TABLE <index_name>;

Example:
• DROP TABLE EMPLOYEE;

1.1.3 ALTER
An existing database object can be modified using the alter command. Alter command can do
following changes to any table-

 Add new columns.

 Add new integrity constraints.

 Modify existing columns.

2|Page
 Drop integrity constraints.

Syntax
General Syntax of the ALTER command is mentioned below −

For adding a new column:

ALTER TABLE <table_name> ADD <column_name>

For renaming a table:


ALTER TABLE <table_name> RENAME To <new_table_name >

For modifying a column:


ALTER TABLE <table_name> MODIFY <column_name > <data type >

For deleting a column:

ALTER TABLE <table_name> DROP COLUMN <column_name>

Example:
• ALTER TABLE STU_DETAILS ADD(ADDRESS VARCHAR2(20));
• ALTER TABLE STU_DETAILS MODIFY (NAME VARCHAR2(20));

1.1.4 TRUNCATE

It is used to delete all the rows from the table and free the space containing the table.
Syntax:
TRUNCATE TABLE table_name;
Example:
TRUNCATE TABLE EMPLOYEE;

1.2 DBMS System Architecture

1.2.1 Database Users and User Interfaces:

Users of database systems can be divided into four categories based on how they anticipate to
interact with the system.

 Naive users :
Users who interact with the system through established user interfaces, such as online
or mobile applications, are known as naive users. A forms interface is a standard user interface for
new users, where the user can fill in suitable fields of the form. Users with no access to the database
can also view read reports generated by the database.

3|Page
• Application programmers:

– Professionals who build application programs are known as application programmers.


To create user interfaces, application programmers have a variety of options.
– Sophisticated users:

Users with advanced skills interact with the system without having to write programs. Instead,
they use a database query language or tools like data analysis software to construct their
requests. This category includes analysts who send queries to study data in the database.

 Storage Manager

The storage manager is a database system component that serves as an interface between the
database's low-level data and the application programs and queries that are sent to it. The relationship
is the responsibility of the storage manager with the help of the file manager.

The raw data is saved on the hard drive using the operating system's file system. The storage
manager converts DML statements into file-system commands at the lowest level. As a result, the

4|Page
storage manager is in charge of storing, Retrieving and updating information from a database.

The following are the components of the storage manager:


 Authorization and integrity manager:
Which verifies that integrity restrictions are met and that users have the authority to access
data.
• A transaction manager:
Ensures that the database is always in the same state (correct) despite system failures, the
state is maintained, and concurrent transaction executions continue without any clashes.

 File Manager:

The file manager is in charge of allocating disc storage space and the data structures that are used to
represent information saved on disc.

 Buffer Manager:
– The buffer manager is in charge of getting data from disc storage into main memory and
determining what data to cache there. The buffer manager is an important component of
the database system because it allows the database to process large amounts of data.
– Sizes that are significantly larger than the main memory size.
 Data Files:
The database itself is stored in data files.
 Data Dictionary:
Data dictionary, which keeps track of metadata on the database's structure, particularly the
schema.
 Indices:
– Indices can be used to enable quick access to data objects. A database index, like the
index in this book, gives links to data items that have a specific value.
– For instance, we could use an index to locate the instructor record for a specific course.

– ID, or a list of all teacher entries with a specific name.

The Query Processor


 DDL Interpreter:
– The DDL interpreter parses DDL statements and saves the definitions in the data
dictionary.
 DML Compiler:
– DML compiler, which converts DML statements into evaluations in a query language

– The query-evaluation engine's plan consists of low-level instructions.

A query can usually be converted into one of several different evaluation strategies, all of which yield
the same result. The DML compiler also does query optimization, which means it chooses the least
expensive evaluation plan from a list of options.

Query evaluation engine:

– Query evaluation engine which executes low-level instructions generated by the DML
compiler.

5|Page
1.2.2 Database Administrator

One of the key benefits of adopting DBMSs is that they provide central control over both the data and
the programs that use it. A database administrator is someone who has such centralized authority over
the system (DBA).
The functions of a DBA include:
• Schema definition
By executing a set of data definition statements in the DDL, the DBA generates the original
database schema.
• Storage structure and access-method definition.
The DBA may set some parameters for the data's physical organization and the indices that
will be produced.
• Schema and physical-organization modification.
Changes to the schema and physical organization are made by the DBA to reflect the
organization's evolving needs or to improve performance.
• Granting of authorization for data access
The database administrator can control which parts of the database different users have
access to by providing different forms of authorization. When a user attempts to access data in
the system, the database system examines the authorization information in a particular system
structure.

• Routine maintenance:

The database administrator's routine maintenance activities include:


 Backing up the database on external servers on a regular basis to prevent data loss in
the event of disasters such as flooding.
 Ensuring that there is sufficient free disc space for routine operations and
updating disc space as needed.
 Monitoring database jobs and ensuring that performance isn't harmed by extremely
expensive tasks submitted by a few users.

1.3Overview of SQL
 Structured Query Language (SQL) is an acronym for Structured Query Language.
 In a relational database management system, it is used to store and manage data (RDMS).It is
a Relational Database System (RDBMS) standard language.
 It allows users to make relational databases and tables, as well as read, update, and remove
them. SQL is the standard database language used by every RDBMS, including MySQL,
Informix, Oracle, MS Access, and SQL Server.

1.3.1 Rules
 The structure query language does not care about
capitalization. In general, SQL keywords are

6|Page
expressed in uppercase.
 SQL statements are based on text lines.
 On a single or several text lines, we can utilize a
single SQL statement.
 You can conduct the majority of database tasks
with SQL statements.
 Tuple relational calculus and relational algebra
are used in SQL.
1.3.2 Process of SQL
– When a SQL command is run against any RDBMS, the system selects the optimal approach
to execute the request, and the SQL engine decides how to interpret the task.
– Various components are used in the process. Optimization Engine, Query Engine, Query
Dispatcher, Classic, and so on are examples of these components.

1.3.3 Characteristics of SQL:


 SQL is a simple programming language to pick up.
 Data from relational database management systems is accessed using SQL.
 SQL is capable of executing database queries.
 For describing the data, SQL is employed.
 SQL is a programming language that is used to define and modify data in databases.
 The database and table are created and deleted with SQL.
 A view, stored procedure, or function in a database are all created using SQL

1.3.4 Advantages of SQL:


– SQL is a simple programming language to pick up.
– Data from relational database management systems is accessed using SQL.

7|Page
– SQL is capable of executing database queries.
– For describing the data, SQL is employed.
– SQL is a programming language that is used to define and modify data in databases.
– The database and table are created and deleted with SQL.
– A view, stored procedure, or function in a database are all created using SQL

1.3.5 Types of SQL:


– SQL commands are instructions. It is used to communicate with the database. It is also used
to perform specific tasks, functions, and queries of data.
– SQL can perform various tasks like create a table, add data to tables, drop the table, modify
the table, and set permission for users.

1.4 Data Manipulation Commands


– DML commands are used to modify the database. It is responsible for all form of changes in
the database.
– The command of DML is not auto-committed that means it can't permanently save all the
changes in the database. They can be rollback.
Here are some commands that come under DML:
• INSERT
• UPDATE
• DELETE
1.4.1 INSERT
INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a table.
Syntax:

INSERT INTO TABLE_NAME (col1, col2, col3 ... col N) VALUES (value1, value2, value3
... valueN);
Or

8|Page
INSERT INTO TABLE_NAME VALUES (value1, value2, value3 ... valueN);

For example:
INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS");

1.4.2 UPDATE
UPDATE: This command is used to update or modify the value of a column in the table.
Syntax:

UPDATE table_name SET [column_name1= value1,...column_nameN = valueN] [WHERE CON


DITION]

For example:

UPDATE students
SET User_Name = 'Sonoo'
WHERE Student_Id = '3'

This unit summarizes about the definition of database systems and goal of DBMS. Practical
Applications of DBMS and the drawbacks of File Processing system is given clearly. The
content helps the reader to improve the data abstraction and views of Data.
1.4.3 DELETE

DELETE: It is used to remove one or more row from a table.


– Syntax:
– DELETE FROM table_name [WHERE condition];
– For example:
– DELETE FROM javatpoint
WHERE Author="Sonoo";

1.5 SET Operations


The SQL Set operation is used to combine the two or more SQL SELECT statements.
Types of Set Operation
 Union
 Union All
 Intersect
 Minus
1.5.1 UNION

 The SQL Union operation joins the results of two or more SQL SELECT queries together.
 The number of data types and columns in both tables on which the UNION operation is
performed must be the same in order to perform the union operation.
 Duplicate rows are removed from the result set using the union method.
Syntax
SELECT column_name FROM table1

9|Page
UNION
SELECT column_name FROM table2;

ID NAME

1 Jack
2 Harley
3 Joseph
• Example: The First Table

ID NAME

3 Joseph
4 Steve
5 Daniel
• The Second Table:

10 | P a g e
• Union SQL query will be:
SELECT * FROM First

UNION

SELECT * FROM Second;

ID NAME

1 Jack
2 Harley
3 Joseph
4 Steve
5 Daniel
• The resultset table will look like:

1.5.2 UNIONALL

Union All operations are equivalent to those of the Union. It returns the set without sorting or
deleting duplicates.
Syntax:
SELECT column_name FROM table1
UNION ALL
SELECT column_name FROM table2;
Example: Using the above first and Second table.
Union All query will be like:
SELECT * FROM First
UNION ALL
SELECT * FROM Second;

ID NAME
11 | P a g e
1 Jack

2 Harley

3 Joseph

3 Joseph

4 Steve

5 Daniel
• The resultset table will look like:

1.5.3 INTERSECT
 It's used to join two SELECT statements together.
 The common rows from both SELECT statements are returned by the Intersect procedure.
 The number of data types and columns in the Intersect operation must be the same.
 There are no duplicates, and the data is arranged in ascending order by default.
Syntax
SELECT column_name FROM table1
INTERSECT
SELECT column_name FROM table2;
Example:
Using the above first and Second table.
 Intersect query will be:
SELECT * FROM First

INTERSECT

SELECT * FROM Second;

The

ID NAME

3 Joseph
resultset table will look like:

1.5.4 MINUS

12 | P a g e
 It combines the results of two SELECT statements into a single statement.
 The minus operator is used to show rows that are present in the first query but not in the
second.
 There are no duplicates, and the data is sorted ascending by default.
Syntax:
SELECT column_name FROM table1
MINUS
SELECT column_name FROM table2;
Minus query will be:
SELECT * FROM First
MINUS
SELECT * FROM Second;
The resultset table will look like:

ID NAME

1 Jack
2 Harley

1.6 SUMMARY
This unit summarizes about the Overview of SQL and the commands of Data definition and
data manipulation. Detailed explanation of Database system Architecture is given. The content
helps the reader to improve the Set Operations.

Questions and Exercises


1. Explain the Architecture of Database System with diagram.
2. List the Set operations with example
3. Give the characteristics of SQL
4. Write some advantages of SQL
5. Differentiate the data definition and data manipulation commands with examples.

References
[1] Abraham Silberschatz, Henry F. Korth, S. Sudharshan, (2011),“Database System Concepts”,

13 | P a g e
Sixth Edition, Tata McGraw Hill
[2] https://www.javatpoint.com/dbms-sql-command

14 | P a g e

You might also like