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

Database Management System

An SSS2 note for 3rd and 4th week
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Database Management System

An SSS2 note for 3rd and 4th week
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

DATABASE MANAGEMENT SYSTEM

• Data – In a database, data refers to the collection of facts, figures, or information that is stored in a
structured format.
• Base – BASE, which stands for Basically Available, Soft state, Eventually consistent, is a data
management principle that provides an alternative to the traditional model for database management.
• Management – Management in a Database Management System (DBMS) refers to the set of activities
involved in creating, organizing, maintaining, securing, and optimizing a database.
• System – In a Database Management System (DBMS), the term “system” typically refers to the software
system used to manage the database.
• A Database Management System is a software package with computer programs that controls the creation,
maintenance, and use of a database. It allows organizations to conveniently develop databases for various
applications.
A database model is basically used by the following users:
1. Developers: design and develop a database.
2. Administrators: keep track on database and check authorization to provide access to the users. (Admin) /
DBA
3. End users: are the group of people who really use the database program. For example, in a school, teachers
and students are the end users as they use the database every day.
Key components of Database
• Columns are referred as fields. A field describes a specific property of a record, that is why a field is also
known as an attribute.
• Rows are referred as records. A single record is also known as tuple.
• A set of characters that represents a valid value is known as data or data value or data item.

Different types of Database Management System

• Relational Database Management System


• Hierarchical Database Management System
• Network Database Management System
• Object-Oriented Database Management System
• Flat file Database Management System
Advantages of Database
1. Reduces Data Redundancy
2. Reduces Data Inconsistency
3. Increases Data Integrity
4. Sharing of Data
5. Sharing of Resources
6. Data Security
7. Privacy
8. Backup & Recovery
Types of Keys in Database
1. Primary Key – A primary key is a field or column that uniquely identifies each record.
2. Composite Primary Key – Composite primary key is a key of two or more attributes that uniquely
identifies the row.
3. Foreign Key – A foreign key is a field or a set of fields in a table that refers to the primary key of another
table.
4. Alternate Key – An alternate key is a candidate key that is not chosen to be the primary key.
5. Candidate Key – A candidate key is a unique key that can be used as a primary key.
DATA TYPES
A field's data type determines what kind of data it can store. The data type determines the kind of the
values that users can store in any given field.
Here are some of the most common data types you will find used in a typical Microsoft Access database.

Type of Data Description Size


Short Text Text or combinations of text and Up to 255 characters.
numbers, including numbers that do
not require calculating (e.g. phone
numbers).
Long Text Lengthy text or combinations of text Up to 63, 999 characters.
and numbers.
Number Numeric data used in mathematical 1, 2, 4, or 8 bytes (16 bytes
calculations. if set to Replication ID).
Date/Time Date and time values for the years 8 bytes
100 through 9999.
Currency Currency values and numeric data 8 bytes
used in mathematical calculations
involving data with one to four
decimal places.
AutoNumber A unique sequential (incremented by 4 bytes (16 bytes if set to
1) number or random number Replication ID).
assigned by Microsoft Access
whenever a new record is added to a
table.
Yes/No Yes and No values and fields that 1 bit.
contain only one of two values
(Yes/No, True/False, or On/Off).
In the previous versions of Access, you will notice a difference for two of those data types.
In Access 2013, we now have two data types — short text and long text. In previous versions of Access these
data types were called text and memo.
The text field is referred to as short text and your memo field is now called long text.
Here are some of the other more specialized data types, you can choose from in Access.
Data Types Description Size
Attachment Files, such as digital photos. Up to about 2 GB.
Multiple files can be attached per
record.
OLE objects OLE objects can store pictures, Up to about 2 GB.
audio, video, or other BLOBs
(Binary Large Objects)
Hyperlink Text or combinations of text and Up to 8,192 (each part of a
numbers stored as text and used Hyperlink data type can
as a hyperlink address. contain up to 2048
characters).
Lookup The Lookup Wizard entry in the Dependent on the data type
Wizard Data Type column in the Design of the lookup field.
view is not actually a data type.
When you choose this entry, a
wizard starts to help you define
either a simple or complex lookup
field.

Calculated You can create an expression that You can create an


uses data from one or more fields. expression that uses data
You can designate different result from one or more fields.
data types from the expression. You can designate different
result data types from the
expression.

SQL (Structured Query Language)


SQL (Structured Query Language) is the language used in RDBMS for writing queries. Using SQL, a user can
create queries to fetch and manipulate the data of the database.
The SQL commands are of two types (according to syllabus):
1. Data Definition Language (DDL)
2. Data Manipulation Language (DML)
Data Definition Language (DDL)
These commands are used to define and modify the structure of a database. The commands that fall under
this category are listed as follows:
1. CREATE – It is used to create a new database or table.
• CREATE DATABASE
CREATE DATABASE <DATABASE_NAME>; EXAMPLE:
CREATE DATABASE myschool_db;
• USE DATABASE – To create a table USE Database command is required.
SYNTAX: USE <DATABASE_NAME>;
EXAMPLE: USE myschool_db;
CREATE TABLE
SYNTAX: CREATE TABLE table_name(column_definition1, column_definition2, ........ ,........);

EXAMPLE: CREATE TABLE employee(e_id int(8), e_name char(30));


Que: Write a command and query to create the structure of a table named “student1”.
• Ans: CREATE TABLE Student1 (Roll_No INT, Class CHAR, Name CHAR, Marks INT);
2. ALTER – It is used to modify the structure of an existing database or table.
• TO ADD COLUMN (FIELD)
SYNTAX: ALTER TABLE <Table_Name> ADD COLUMN <Column_Name> <Data_Type>; EXAMPLE:
ALTER TABLE employee ADD COLUMN e_loc char(50);
TO REMOVE/DROP COLUMN (FIELD)
SYNTAX: ALTER TABLE <Table_Name> DROP COLUMN <Column_Name>; EXAMPLE: ALTER TABLE
employee DROP COLUMN e_loc;
3. DROP – Deletes an existing database or table.
TO DROP TABLE
SYNTAX: DROP TABLE <Table_Name>; EXAMPLE: DROP TABLE employee;
TO DROP DATABASE
SYNTAX: DROP DATABASE <Database_Name>; EXAMPLE: DROP DATABASE myschool_db;
4. TRUNCATE – Remove all table records including allocated table spaces, but not the table itself.
SYNTAX: TRUNCATE TABLE <Table_Name>; EXAMPLE: TRUNCATE TABLE employee;
5. RENAME – It is used to change the name of existing database or table.
SYNTAX: ALTER TABLE <Table_Name> RENAME TO <New_Table_Name>;
EXAMPLE: ALTER TABLE employee RENAME TO customers;
Data Manipulation Language (DML)
• A DML (Data Manipulation Language) is a computer programming language used for adding (inserting),
modifying (updating) and data in database. The commands that fall under this category are listed as
follows:
• 1. INSERT – The insert command is used to add one or more records to a table. There are two methods to
use the INSERT command.
Method 1: SYNTAX: INSERT INTO <Table_Name> (Field 1, Field 2,….) VALUES (Value 1, Value 2,….);
EXAMPLE: INSERT INTO employee (‘e_id’, ‘e_name’,) VALUES (1, “Mukesh”);
Method 2: SYNTAX: INSERT INTO <Table_Name> VALUES (Value 1, Value 2,….);
EXAMPLE: INSERT INTO employee VALUES (1, “Mukesh”);
• 2. SELECT – It is used to retrieves or fetch the data from the table.
• TO FETCH ENTIRE RECORD OF TABLE [* means ALL records]
SYNTAX: SELECT * FROM <Table_Name>; EXAMPLE: SELECT * FROM employee;
TO FETCH RECORD OF SELECTED FIELDS FROM TABLE
SYNTAX: SELECT <Field1, Field2,…> FROM <Table_Name>; EXAMPLE: SELECT e_name, e_id FROM
<Table_Name>;
OTHERS ARE:
1. DQL statements are used for performing queries on the data within schema objects.
DQL Command
There is only one DQL command in SQL i.e.

Command Description Syntax

SELECT column1, column2,


It is used to retrieve
SELECT ...FROM table_name
data from the database
WHERE condition;

2. DCL (Data Control Language)


• DCL includes commands such as GRANT and REVOKE which mainly deal with the rights, permissions,
and other controls of the database system.
List of DCL commands:
• Two important DCL commands and their syntax are:

Command Description Syntax


Assigns new privileges to a user
GRANT privilege_type [(column_list)] ON
account, allowing access to
GRANT [object_type] object_name TO user [WITH
specific database objects, actions,
GRANT OPTION];
or functions.

Removes previously granted REVOKE [GRANT OPTION FOR]


privileges from a user account, privilege_type [(column_list)] ON
REVOKE
taking away their access to certain [object_type] object_name FROM user
database objects or actions. [CASCADE];

3. TCL (Transaction Control Language)


Transactions group a set of tasks into a single execution unit. Each transaction begins with a specific task
and ends when all the tasks in the group are successfully completed. If any of the tasks fail, the transaction fails.
• Therefore, a transaction has only two results: success or failure.
List of TCL Commands
• Some TCL commands and their syntax are:
Command Description Syntax

BEGIN
BEGIN
Starts a new transaction TRANSACTION
TRANSACTION
[transaction_name];

Saves all changes made during


COMMIT COMMIT;
the transaction

Undoes all changes made


ROLLBACK ROLLBACK;
during the transaction

Creates a savepoint within the SAVEPOINT


SAVEPOINT
current transaction savepoint_name;

You might also like