Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Computer Science XII

Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

Computer Science-11

GRADE XII

Dipak Pudasaini
Him Koirala
Manoi Kumar Karn
Ramesh Rimal

Approved by Government of Nepal, Ministry of Education, Science & Technology,


Curriculum Development Centre, Bhaktapur, as an Additional Material from 2078 to 2080
Contents

1 Database 1.1 Introduction to data, database, Database system, DBMS 12


Management 1.2 Field, Record, Objects, Primary Key, Alternate key, Candidate key
System 1.3 Advantages of using DBMS
(DBMS)
1.4 DDL (Data Definition Language) and DML (Data Manipulation Language)
1.5 Database Model: Network Model, Hierarchical Model, Relational database
model
1.6 Concept of Normalization: 1NF, 2NF, 3NF
1.7 Centralized Vs. Distributed Database
1.8 Database Security

2 Data 2.1 Basic elements of Communication System: 15


Communication 2.2 Concept of Communication System
and Networking 2.3 Block Diagram of communication System /Model
2.4 Elements of Data Communication/Transmission
2.5 Simplex, Half duplex and Full duplex communication mode
2.6 Concept of LAN and WAN
2.7 Transmission Medium: Guided and Unguided
2.8 Transmission impairments terminology (Jitter, Singing, Echo, Crosstalk,
Distortion, Noise, Bandwidth, Number of receivers)
2.9 Basic concept of Networks Architecture: Client-Server and Peer-to-peer
2.10 Some Basic Terms and Tool Used in Computer
Network: IP Address, Sub Net Mask and Gateway, MAC address, Internet,
Intranet, Extranet
2.11 Network Tool: Packet tracer, Remote Login
2.12 Network Connecting Devices: NIC, Modem, router, switch
2.13 Network Topologies: Bus, Ring and star topology
2.14 Basic Concept OSI Reference Model
2.15 Internet Protocol Addressing

3 Web 3.1 Introduction 12


Technology 3.2 Server side and Client Side Scripting
II 3.3 Introduction of internet technology
3.4 Adding Java script to HTML page
3.5 Java script fundamental
3.6 Java Script Data types
3.7 Variables and operators
3.8 Functions and control structure if-else, if-elseif, switch-case, for, while, do
while loop
3.9 Object based programming with Java Script and Event handling
3.10 Image, event and form objects
3.11 Form validation, JQuery
3.12 Server Side Scripting using PHP
3.13 Introduction to PHP: Hardware and Software Requirements
3.14 Object oriented programming with server side scripting
3.15 Basic PH P syntax
3.16 PH P data types
3.17 Basic Programming in PHP
3.18 Operators (Arithmetic, logical, comparison, operator precedence)
3.19 Variables Manipulation
3.20 Database Connectivity
3.21 Connecting server side script to database
3.22 Making SQL queries
3.23 Fetching data sets getting data about data
3.24 Creating SQL database with server side scripting
3.25 Displaying queries in tables
4 Programming 4.1 Review of C programming concept 12
inC
4.2 Functions
4.2.1 Concept of library and user defined functions and advantages
4.2.2 function definition, prototype, call and return statements
4.2.3 Accessing a Function by passing values
4.2.4 Concept of storage: automatic and external
4.2.5 Concept of Recursion: factorial and Fibonacci problems
4.3 Structures and Unions
4.3.1 Structure: Definition, Declaration, Initialization and Size of
Structure.
4.3.2 Accessing member of structure
4.3.3 Array of structure
4.3.4 Union: Definition, Declaration
4.3.5 Difference between union and structure.
4.4 Pointers
4.4.1 Definition of Pointer
4.4.2 Address (&) and indirection (•) operator
4.4.3 Pointer Expression and Assignment
4.4.4 Call by values and call by reference
4.5 Working with Files
4.5.1 Concept of Data File
4.5.2 Sequential and Random File
4.5.3 File manipulation function: putw, getw, putc, getc, fscanf, fprintf
4.5.4 Opening, Reading, Writing and Appending data file

-----<
5 Object-oriented 5.1 Programming paradigms: procedural, structural and object oriented 10
Programming 5.2 Features of OOP: Class, Object, Polymorphism and Inheritance
(OOP) 5.3 Advantages of COP
5.4 Application of OOP

6 Software 6.1 Software Project Concept 10


Process Model 6.2 Concept of software development process
(SPM} 6.3 Concept SDLC life cycle
6.4 System Analyst Vs SOftware Engineer
6.5 Requirement Collection Methods
6.6 Concept of system design
6.7 Software and quality
6.8 Software development model: waterfall, prototype, agile

7 Recent Trends 7.1 Concept of Artificial Intelligence (AI) and Robotics 9


in Technology 7.2 Concept of Cloud Computing
7.3 Concept of Big Data
7.4 Concept of Virtual Reality
7.5 Concept of e-com, e-medicine, e-gov.
7.6 Concept of Mobile Computing
7.7 Concept of Internet of things (loT)

Total 80
CHAPTER 1 2.10 Some Basic Terms and Tools 56
2.11 Network Tool: Packet Tracer, Remote
DATABASE MANAGEMENT Login 59
SYSTEM (DBMS) 2.12 Network Connecting Devices 61
1.1 Introduction: Data, Information, Database
2.13 Network Topologies 62
and DBMS 2
2.14 Basic Concept OSI Reference Model 65
1.2 Field, Record, Objects, Primary Key,
Alternate key, Candidate key 3 2.15 Internet Protocol Addressing 66
1.3 Advantages and Disadvantages of DBMS 4 Keywords 68
1.4 DDL (Data Definition Language) and DML Exercise 69
(Data Manipulation Language) 6 Case Study 71
1.5 Database Model: Network Model,
Hierarchical Model, Relational database
CHAPTER 3
Model 7
1.6 Concept of Normalization: 1 NF, 2NF, 3NF 10 WEB TECHNOLOGY II
1.7 Centralized Vs. Distributed Database 14 3.1 Introduction 73
1.8 Data Security 16 3.2 Server Side and Client Side Scripting 73
Keywords 35 3.3 Introduction of Internet Technology 74
Exercise 36 3.4 Adding java Script to HTML Page 76
Case Study 37 3.5 java Script Fundamental 77
3.6 java Script Data Types 79
CHAPTER 2 3.7 Variables and Operators 80

DATA COMMUNICATION 3.8 Functions and Control Structure 85

AND NETWORKING 3.9 Object Oriented Programming and Event


Handling 92
2.1 Basic Elements of Communication
System 40 3.10 Image, Event and Form Objects 98

2.2 Concepts of Communication System 42 3.11 Form Validation and jQuery 102

2.3 Block Diagram of Communication System/ 3.12 Server Side Scripting using PHP 106
Model 43 3.13 Introduction to PHP: Hardware and
2.4 Elements of Data Communication/ Software Requirements 106
Transmission 43 3.14 Object oriented programming with server
2.5 Simplex, Half Duplex and Full Duplex side scripting 108
Communication Mode 44 3.15 Basic PHP syntax 109
2.6 Concept of LAN and WAN 45 3.16PHPdatatypes 110
2.7 Transmission Media 48 3.17 Basic Programming in PHP 113
2.8 Transmission Impairments Terminology 52 3.18 Operators (Arithmetic, logical, comparison,
2.9 Basic Concepts of Network Architecture 54 operator precedence) 118
3.19 Variables Manipulation 121 Exercise 211
3.20 Database Connectivity 122 Lab Work 2: Structure and Union 212
3.21 Connecting server side script to Case Study 212
database 123
4.4 Pointers 213
3.22 Making SQL queries 125
4.4.1 Definitionofpointer 213
3.23 Fetching data sets getting data about 4.4.2 The Address (&) and Indirection
data 128 (*) Operator 213
3.24 Creating SQL database with server side 4.4.3 Pointer Expression and
scripting 129 Assignment 214
3.25 Displaying queries in tables 131
4.4.4 Call by values and call by
Keywords 133 reference 218
Exercise 134 Keywords 220
Case Study (Project work) 136 Exercise 220
Lab Works 3: Pointer 221
Case Study 221
CHAPTER 4 4.5 Working with Files 222
PROGRAMMING CONCEPT 4.5.1 Concept of Data Files 222
4.1 Review of C programming concept 139 4.5.2 Sequential and Random
Access File 222
4.2 Functions 171
4.5.3 File manipulation function: putw,
4.2.1 Concept of library and user defined
getw, putc, getc, fscanf, printf 223
functions and advantages 171
4.5.4 Opening, reading, writing and
4.2.2 Accessing a Function by passing
appending on /from data File 229
values 182
Keywords 234
4.2.3 Concept of Storage: automatic and
external 184 Exercise 235
4.2.4 Concept of Recursion: factorial and Lab Works 4: Working with Files 237
Fibonacci problems 187 Case Study 237
Keywords 193
Exercise 194 CHAPTER 5
Case study 195
OBJECT ORIENTED
4.3 Structures and Union 196
PROGRAMMING (OOP)
4.3.1 Structure: Definition, Declaration,
5.1 Programming paradigms: procedural,
Initialization and Size of Structure 196
structural and object oriented 240
4.3.2 Accessing member of structure 198
5.2 Feature of OOP: Class, Object,
4.3.3 Array of structure 201 Polymorphism and Inheritance 242
4.3.4 Union: Definition, Declaration 203 5.3 Advantages of OOP 247
4.3.5 Differences between structure and 5.4 Application of OOP 247
union 204
Keywords 248
Workout Examples 206
Exercise 249
Keywords 211
Case Study 250
CHAPTER 6 CHAPTER 7

SOFTWARE PROCESS MODEL RECENT TRENDS


(SPM) IN TECHNOLOGY
6.1 Software Project Concept 252 7.1 Concept of Artificial Intelligence and
6.2 Concept of software development Robotics 285
process 255 7.2 Concept of Cloud Computing 290
6.3 Concept SDLC life cycle 255 7.3 Concepts of Big Data 293
6.4 System Analyst Vs Software Engineer 263 7.4 Concept of Virtual Reality 296
6.5 Requirement Collection Methods 264 7.5 Concept of e-com, e-medicine, e-gov 300
6.6 Concept of System Design 265 7.6 Concept of Mobile Computing 305
6.7 Software and quality 273 7.7 Concept of Internet of Things (loT) 307
6.8. System Development Model: waterfall, Keywords 308
prototype, agile 273 Exercise 309
6.9 Case Study 278
Case Study 312
Keywords 279
Exercise 280
At the end of this unit, students will be able to
:> understand data, information, database,
DBMS
:> understand the basic concept of different
database models
:> understand the basic concept of normalization
and its types (1 NF, 2 NF and 3 NF)
:> know about SQL with its basic structures and
sub languages (DDL, DML and DCL)
:> compare centralized and distributed database
systems
:> understand the basic concept of data security
:> design database system using DBMS software
(My-SQL)

:> For teaching this unit, we are assigned


approximate thirteen theory classes and twenty
five practical classes.
:> Let the students understand data, information,
database, DBMS with its objectives,
advantages and disadvantages with the help of
appropriate examples
:> Let the students understand the basic concept
of different database models with the help of
examples and diagrams
:> Let the students understand the basic concept
of normalization and its types with the help of
examples and table
:> Let the students know about SQL with its
basic structures and sub languages (DDL,
DML and DCL) with the help ofSQL
commands
:> Let the students compare centralized and
distributed database systems with the help of
diagrams
:> Lastly, let the students understand data
security with the help of real life examples and
cases
:> Lastly, let the students design database system
using DBMS software (MySQL)in order
to make them able create different objects of
DBMS
1.1 Introduction: Data, Information, Database and DBMS
Information is the backbone of any organization. It is the most critical resource of the
organization. Different methods and techniques have been adopted to keep up-to-date
information. Before the invention of the computer, people used to maintain database using
different devices and used to keep records in the paper. With the development of computer
system, methods of processing, techniques of keeping data and information have been
completely changed. Computer has replaced millions of files and folders. It can store a large
amount of data in a small place of a disk. Let us discuss some important terms of database.
Data: Data is raw facts which are composed of alphabets, digits and other symbols. It may
or may not give any sense. For example: 1, Rubina, 5.4, 2, Rasbina etc.
Information: When data are processed using a database program or software, they are
converted to the meaningful result, called information. In other words, the output of data
processing is called information. It is an organized collection of related data, which gives
a complete sense. Example: Information about weight of 3 students.

Height of students
I I

1 Rubina 5.4
2 I Rasbina 5.6
3 Rahul 5.8

Database: Database is a collection of interrelated data of objects or entities stored in


tabular form. Database gives very useful information for an organization during data
manipulation and decision making. It provides a base or foundation for managing large
volume of data in well organized manner. For example: Phone Diary, Result Sheet,
Customer Records and Price List etc.

Database Management System (DBMS)


A database management system is computerized records keeping system. It is a software
that defines, manipulates and manages the database. It allows to access the files, update
the records and retrieve data as requested. In other words, DBMS is defined as the
collection of interrelated data and set of programs to access those data.

POINTS TO REMEMBER

I
DBMS is defined as the collection of interrelated data and set of programs to
access those data. The collection of data is usually database which contains the
information about any particular organization and set of programs is special
type language to manage those database.

The primary goal of a DBMS is to provide an efficient and effective environment for both
data retrieval and storing data in database. Commercially database management system
is called database packages or also called database engine. Some examples are FoxPro,
DBase, Sybase, MS Access, My SQL, MS SQL Server, Oracle and DB2 etc.

Approved by Curriculum Development Centre, Nepal


Figure 1.1: Logical view of database system

The above figure shows the logical structure of database management system. Users may
be persons or application from external environment that supplies various requests to the
system. Database requests mean the various activities from users. The database system
checks for the requests and performs various activities as per the need of users. Some
major database activities are:
• Adding new file to the database
• Inserting data into the database file
• Retrieving/Viewing data from the database
• Updating data in existing database file
• Deleting data from the database file
• Removing files from the database

POINTS TO REMEMBER

I Database is a collection of interrelated data of entities or objects which is stored


in a computer in such a way that it can be easily accessed by user.

Assignment 1
1. Define database.
2. Compare data and database.

1.2. Field, Record, Objects, Primary Key, Alternate


key, Candidate key
1. Field: A field is the property or attributes of a table. Examples: SN, Name, Weight are
fields.
2. Record: A record is the collection of interrelated fields. Example: there are three
records in above table.
3. Table: A table is the arrangements of rows and columns. Each table must have unique
name and must be simple. A row defines a record and a column defines a field in a
table.

Approved by Curriculum Development Centre, Nepal


Objects: Objects are used in database to store or reference data. So, object holds data for
manipulation and display it in the proper format. Main components of DBMS are field,
record and table. Example of components of objects are:

Height of students
SN Height (Feet, Inch)
1 Rubina 5.4
2 I Rasbina I 5.6
3 Rahul 5.8

Primary Key: The field or fields that contain the unique value can be set as primary key.
It does not permit duplicate or null values. For example, the registration number of a
student is a primary key.

Table: Student
Primary key Reg_Number Name
1001 Hari
1002 Sita
1003 Ram

Here Reg_Number is the primary key.


Alternate key: Alternate is not a primary key but combining one or more columns it make
unique. So, alternate key associated with one or more columns whose values uniquely
identify every row in the table. Each alternate key can generate a unique index or a unique
constraint in a target database. For example, where the primary key for a table may be
the student id, the alternate key might combine the first, middle, and last names of the
student.

Candidate Key: Occasionally we may encounter a relation in which there is more than
one attributes possessing the unique identification property. So, all attribute combinations
inside a relation that can provide the unique record in a relation are called candidate keys.

1.3 Advantages and Disadvantages of DBMS


Advantages
• Sharing data: Data stored in a database can be shared. It refers to the capacity that
makes data simultaneously accessible by many users without any interference.
• Reduced data redundancy: The same data may be duplicated at many times or
places, is called data redundancy, DBMS reduces such type of duplication of data
from database.
• Data backup and recovery: DBMS provides backup facilities to store data for future

Approved by Curriculum Development Centre, Nepal


use. If any files or data lost in any computer, it is possible to restore them from
database server.
• Inconsistency avoided: When the same data is duplicated and changes are made at
one site, and not on other sites, it causes data inconsistency. DBMS avoided such type
of data inconsistency.
• Data integrity: Data integrity means data accuracy, consistency and up to date. A
DBMS should provide capabilities for defining and enforcing constraints for data
integrity.
• Data security: In database system, an unauthorized person cannot access data from
database. Although various departments may share data in database, access to
specific information that can be limited to selected users.
• Data independence: Description of the data (Schema) is stored in one central place.
Therefore, applications do not have to recompile when the format of the data changes.
• Multiple user interfaces: DBMS provides variety of interfaces for various users.
It provides query language interface, forms and command interfaces so that users
interact easily with the database.
• Process complex query: It provides different methods such as view, trigger, index
etc. to process complex queries.

Disadvantages
• Expensive: Database software is very expensive for large computer systems. It also
requires overhead costs for maintaining and integrity functions.
• Changing technology: It is fast changing technology.
• Needs Technical Training: It is complex to understand and implement. So, proper
training is required for staff to work properly in the database system.
• Backup is needed: It needs to explicit back up. This adds costs as new storage space
are needed to hold the data

POINTS TO REMEMBER

I A DBMS is a set ofprograms that manages the database files. It allows accessing the
files, updating the records and retrieving data as requested.

Assignment 2
1. Describe primary key, alternate key and candidate key with
examples.
2. Write advantage of DBMS.

Approved by Curriculum Development Centre, Nepal


1.4 DDL (Data Definition Language) and DML
(Data Manipulation Language)
SQL stands for Structured Query Language. It is an international standard database
query language for accessing and managing data in the database. SQL was introduced
and developed by IBM in early 1970s. IBM was able to demonstrate SQL which could be
used to control relational databases. SQL is not a complete programming languages, it is
only used for communicating with database. It provides platform which allows the user
to query a database without getting depth knowledge of the design of the underlying
tables. SQL has statements for data definition, data manipulation and data control. A
query is a request to the DBMS for the retrieval, modification, insertion and deletion of
the data from the database.

SQL (Structured Query Language) Pronounced as "See" -"Quell" is made of three sub
languages DDL, DML and DCL.
Basic Structure of SQL
To create a table
CREATE table table_name (fieldl data_type, field2 data_type, .............);
For example:
CREATE table Student (Sid NUMBER (4), Name CHAR (25));
To insert records into a table Student
INSERT into table name
VALUES (List of values);
For example: INSERT into Student
VALUES (22, 'Ram');
To display records from a table
SELECT fieldl, field2 ...
FROM tables name
For example: SELECT Sid, Name form Student

1 DDL (Data Definition Language): DDL is used by the database designers and
programmers to specify the content and structure of the table. It is used to define
the physical characteristics of records. It includes commands that manipulate the
structure of objects such as Views, Tables, and Indexes etc. Examples of these
Commands are Create, Alter, Drop, Rename etc.
To create a table
CREATE table table_name (fieldl data_type, field2 data_type, .............);

Approved by Curriculum Development Centre, Nepal


For example:
CREATE table Student (Sid NUMBER (4), Name CHAR (25));

2 DML (Data Manipulation Language): DML is related with manipulation of records


such as retrieval, sorting, display and deletion of records or data. It helps user to
use query and display reports of the table. So, it provides techniques for processing
the database. It includes commands to manipulate the information stored in the
databases. Examples of these Commands are Insert, Delete, Select and Update etc.
To insert records into a table Student
INSERT into table name
VALUES (List of values);

For example: INSERT into Student


VALUES (22, 'Ram');

POINTS TO REMEMBER

I
DDL is used to define the physical characteristics of records. DML is related
with manipulation of records such as retrieval, sorting, display and deletion of
records or data.

1. Differentiate between DDL and DML.

1.5 Database Model: Network Model, Hierarchical


Model, Relational database Model
There are different forms of database management system, each characterized by the
way where data are defined and structured, called database model. It is the organizing
principles of records in secondary storage. Following are the different architectures:

• Hierarchical Database Model


• Network Database Model
• Relational Database Model

Hierarchical Database Model


Hierarchical database model is one of the oldest type database models. In this model
data is represented in the form of records. Each record has multiple fields/ attributes.
All records are arranged in database as tree like structure. The relationship between the
records is called parent child relationship in which any child record relates to only a

Approved by Curriculum Development Centre, Nepal


single parent type record. In the figure below, there are parent records at the top level
with high privileges and child records at bottom level. There are three types of records:
students, management and department chief records.

Advantages
• It is the easiest model.
• It has one or more attributes.
• The searching is fast and easy, if parent is known.
• It supports one-to-one and one-to-many relationship.

Disadvantages
• It is old fashioned, outdated database model.
• It does not support many-to-many relationship.
• The dependency on parent node is not beneficial always.
• It increases redundancy because same data is to be repeated in different places.

Records (Principal)

Employee Records
(Employee)

Figure 1.2: Hierarchical Database Model

1. Draw a figure to show example of hierarchical database model.

Network Database Model


The network database model replaced hierarchical database model due to some
limitations on the model. Suppose if an employee relates to two departments, then the
hierarchical database model cannot able to arrange records in proper place. So network
database model was emerged to arranged non- hierarchical database. The structure of
database is more like graph rather than tree structure. A network database model consists

Approved by Curriculum Development Centre, Nepal


of collection of records which are inter-related to each other with the help of relationship.
Each record has multiple fields and each field has only one data value. In figure below,
exam records relate to management and students, and similarly employee records relate
to department chief as well as management. In this model, each record in the database
can have multiple parents that is the relationships among data elements can have many
to many relationships.

Records (Principal)

Figure 1.3: Network Database Model

Advantages
• It accepts many-to-many relationship, so it is more flexible.
• The searching is faster because of multidirectional pointers.
• The network model is simple and easy to design.
• It reduces redundancy because data shouldn't be repeated if same data is needed.

Disadvantages
• It is difficult to handle the relationship in complex programs.
• There is less security because of sharing data.
• It increases the processing overhead due to the complex relationship.

Relational Database Model


In relational database model, the data is organized into tables which contain multiple rows
and columns. These tables are called relations. A row in a table represents a relationship
among a set of values. Since a table is a collection of such relationships, it is generally
referred to the mathematical term relation, from which the relational database model
derives its name. It is also known as RDBMS.

POINTS TO REMEMBER

I The database system which stores and displays data in tabular format ofrows and columns,
like spreadsheet, is known as Relational Database Management System (RDBMS ).

Examples of RDBMS are Oracle, SQL, MS-Access, MySql etc.

Approved by Curriculum Development Centre, Nepal


We notice from below table (Student and Subject), here each student has a unique roll
number and has marks of Math, English and Computer. Here, Roll makes relation
between these two tables.

Table: Student
Roll Name
1 Hari 1 80 90 95
2 Sita 2 90 80 85

3 Ram 3 95 95 95

For example, if we make relation between Student and Subject, we can get following:
'I • I English Ill I

1 Hari 80 90 95
2 Sita 90 80 85

3 Ram 95 95 95

Advantages
• The breaking of complex database table into simple database table becomes possible.
• Database processing is faster than other model.
• There is very less redundancy (repetition of data).
• The integrity rules can easily be implemented.

Disadvantages
• It is more complex than other models.
• There are too many rules because of complex relationships.
• It needs more powerful computers and data storage devices.

Assignment 5
1. Compare between Network database model and Relational database
model with diagram.

1.6 Concept of Normalization: 1NF, 2NF, 3NF


Normalization is a database design process in which complex database table is broken
down into simple separate tables. It makes data model more flexible and easier to
maintain. E.F. Codd has introduced few rules for normalizing the database in 1970 and
these rules are known as the normal forms. In other words, there are different steps in
Data Normalization, which are called normal forms. This process minimizes and controls
the duplication of data in the database and also provides a rapid search for data from the
database. It reduces the complexity of database.

Approved by Curriculum Development Centre, Nepal


There are two goals of the normalization process: eliminating redundant data (for
example, storing the same data in more than one table) and ensuring data dependencies
make sense (only storing related data in a table).

Types of Normalization
Normalization can be a complex process with many rules in many layers. There are five
levels of normalization process as shown in figure 2.7. But we discuss only three normal
forms.
lNF
• First Normal Form (lNF) 2NF
• Second Normal Form (2NF) 3NF
4NF
• Third Normal Form (3NF) SNF

The relation first check for lNF, if not convert it


into lNF. Similarly the relations are checked for
2NF, 3NF, 4NF and SNF.
Figure 1.4: Normal Form
POINTS TO REMEMBER

I Normalization is the process of decomposing a big table into many smaller


tables to reduce redundancies and made data model more flexible.

Benefits of Normalization
• The dependency between the data fields is identified.
• The redundancy in database is minimized.
• Data model is made more flexible and easier to maintain.
• It improves faster sorting and index creation.
• It improves the performance of the database system.
• It simplifies the structures of tables.
• It avoids the loss of information.

Assignment 6

1. What is normalization? Write advantages of normalization.

Approved by Curriculum Development Centre, Nepal


Normalization Process
For our reference, we take the following set data/table (Table: Library): LIBRARY
(member_id, member_name, book_code, book_name, issue_date, return_date)

member_
member_id book_code book_name issue_date return_date
name
R01 Rabi 5002 DBMS 15/01/2006 25/01/2006

A02 Alok 5005 c 17/01/2006 24/01/2006

R01 Rabi 5007 Network 25/01/2006 NULL

A02 Alok 5002 DBMS 27/01/2006 NULL

Note: The relation stores the information about the issue and return of a book in a Library
to its member. A member can issue many books. A book cannot be issued again unless it
is returned. The null value in return_date is considered as the book has not returned yet.

1NF (First Normal Form)


First normal form (1NF) sets the very basic rules for an organized database:

• The data field should be an atomic.


• It eliminates duplicate rows and columns from the same table.
• It minimizes the data redundancy in the database table.

In above example member_name field is not atomic, so it is divided into member_fname


& member_lname.

LIBRARY (member_id, member_fname, member_fname, book_code, book_name, issue_


date, issue_retum)

I
member_id member_fname I member_lname Ibook_code I book_name I issue_date I return_date
R01 Rabi Rai 5002 DBMS 15/01/2006 25/01/2006
A02 Alok Karn 5005 C Programming 17/01/2006 24/01/2006
R01 Rabi Rai 5007 Network 25/01/2006 NULL
A02 Alok Karn 5002 DBMS 27/01/2006 NULL

Now the given relation is in 1NF.

2NF (Second Normal Form)


Second normal form (2NF) further addresses the concept of removing duplicative data:
• It should be in the first normal form.
• It identifies data dependencies.
• Non key attributes are functionally depends on key attribute (Primary key).
For example, in order to decompose in 2NF, we have to identify the dependencies in the
relation.

Approved by Curriculum Development Centre, Nepal


member_id (say determines)-> member_fname, member_lname (1)
book_code (say determines)-> book_name (2)
book_code, member_id, issue_date (say determine)-> return_date (3)

member fname
member_id
member_!name

book code
book_name

( issue_date return_date

Figure 1.5:

According to the above functional dependency, the following relations are created.
MEMBER (member_id, member_fname, member_lname) (From FD 1)
BOOK (book_code, book_name) (From FD 2)
ISSUE (book_code, member_id, issue_date, return_date) (From FD 3)

Book
book_code book_name
R01 Rabi Rai 5002 DBMS

A02 Alok Karn 5005 C Programming

5007 Network

ISSUE
member_id book_code issue_date return_date
R01 5002 15/01/2006 25/01/2006
A02 5005 17/01/2006 24/01/2006
R01 5007 25/01/2006 NULL
A02 5002 27/01/2006 NULL

3NF (Third Normal Form)


Third normal form (3NF) goes one large step further:
• It should be in the second normal form.
• It removes transitive dependencies in a table.
A transitive dependency is: if A, B, and C is the attributes in a relation R and A->B,
B-> C then we can derive A->C using functional dependency. There is no transitive
dependency in the above relations, thus no need to further normalization process.

Approved by Curriculum Development Centre, Nepal


For example: if there is tablel: Student (Sid, Name, Cid), table2: Class (Cid, Class) and
table3: Subject (Class, SubName)

Tablet: Student
Sid Name Cld
A1 Aayushi Sll S11 11
A2 Alok S12 S12 12

In order to decompose in 3NF, we have to identify the dependencies in the relation.


Sid (say determines)-> Name, Cid (1)
Cid (say determines)-> Class (2)
Class(say determines)-> SubName (3)
Sid, Name-> SubName (4)

So, we get another Table4: Detail as

Table 4: Student_Detail
. II' I , "

A1 Aayushi Computer
A2 Alok Maths

1. •
Write example of normalization process.

1.7 Centralized Vs. Distributed Database


Centralized Database
Centralized database is simple type which works on a client-server basis. It is located
on a particular (central) location and peripherals are connected with it to storing and
retrieving data as requirement. Centralized database system run on a single computer
system. A computer system may be single user or multi-user. It is only suitable for small
organization and small-scale operation. The database is centralized, so there is no chance
of data modification. Hence, security is not so crucial part here. The maintenance of
database is easier because of data or records are centrally stored. Since data is out from
access of unauthorized persons, so risk factors are also minimized.

Approved by Curriculum Development Centre, Nepal


Figure 1.6: Centralized Database System

Distributed Database
Distributed database is a complex type of database system. It is a collection of multiple
logically interrelated databases which are distributed in many geographical locations.
Data communication is difficult because they should communicate through different
system to different platforms. The problem is security control. It also needs more computer
resources. It is much suitable for such types of organizations, which are distributed all
over the geographical area with similar objectives and similar data sets. In other words, it
is the collection of different centralized database systems in different locations.

Figure 1. 7: Distributed Database System

Approved by Curriculum Development Centre, Nepal


Difference between Centralized and Distributed Database System
Centralized Database System Distributed Database System

Centralized database system is simple type. Distributed Database System is complex type.
They are located in many geographical
They are located on particular location.
locations.
It consists of only one server. It contains servers in several locations.
It is only suitable for small organization and
It is suitable for large organizations.
small-scale operation.
There is less chance of data lost. More chances of data hacking, theft and lost.

Maintenance is not easy and security is low as


Maintenance is easy and security is high.
compare to centralized database system.
Failure of one server does not make the whole
Failure of server makes the whole system down.
system down.
There is no feature of load balancing. There is feature of load balancing.

Data traffic rate is high. Data traffic rate is low.

Cost of centralized database system is low. Cost of distributed database system is high.

Assignment 8
1. Lists advantage and disadvantages of centralized and distributed
database system.

1.8 Data Security


Data security is protection of data in database system against unauthorized access,
modification, failure, losses or destruction. The authorized access means only right
people can get the right access to the right data. There are different causes of database
physical destruction such as fire, water, heat, dust, power failure, theft etc. It might be
accidental loss or physical damage in computer system. In order to protect from such
damages database is stored in different location in different disk (RAID: Redundant
Array of Independent Disk). Different types of data recovery and data locking techniques
are used for the security. Some of the data security methods are:

• Usingproper backup in disks, tapes, CD etc. provides the security of data from the
accidental loss.
• Making physical prevention by using stabilizer and UPS to supply a regular power
through which we can prevent hardware and software from high electricity voltage
and irregular power supply.

Approved by Curriculum Development Centre, Nepal


• Using strong password protection system, making log in the system to prevent data
from unauthorized access to the database.
• By keeping the system under lock or safe place.

Why data security is important?


The data that your company creates, collects, stores, and exchanges is a valuable asset. It is
most important for any organization. Safeguarding it from corruption and unauthorized
access by internal or external people protects your company from financial loss, reputation
damage, consumer confidence disintegration, and brand erosion.

It is important for the following reasons:


Compromised intellectual property: Your intellectual property- trade secrets, inventions,
trademarks -may be critical to your ability to maintain a competitive advantage in your
market. If that intellectual property is stolen or exposed, your competitive advantage may
be difficult or impossible to maintain or recover.

Protect from Damage to brand reputation: Customers or partners may be unwilling to


buy your products or services (or do business with your company) if they don't feel they
can trust you to protect your data or theirs. So, data protection against cyberattacks as
"extremely important" in their decision to purchase from a company.

Costs of repairing breaches and notifying customers: In addition to the cost of


communicating a breach to customer, a breached organization must pay for investigative
activities, crisis management, repair of the affected systems, and more.

Types of data security controls


The following are the main control measures are used to provide security of data in
databases:

1. Authentication
2. Access control
3. Flow control
4. Database Security applying Statistical Method
5. Encryption
6. Backup and recovery

These are explained as following below.

1. Authentication:
Authentication is the process of confirmation that whether the user log in only according
to the rights provided to him to perform the activities of data base. A particular user can

Approved by Curriculum Development Centre, Nepal


login only up to his privilege but he can't access the other sensitive data.
The privilege of accessing sensitive data is restricted by using Authentication.
By using these authentication tools for biometrics such as retina and figure prints can
prevent the data base from unauthorized/ malicious users.

2. Access Control:
The security mechanism of DBMS must include some provisions for restricting access to
the data base by unauthorized users. Access control is done by creating user accounts and
to control login process by the DBMS. So, that database access of sensitive data is possible
only to those people (database users) who are allowed to access such data and to restrict
access to unauthorized persons.

The database system must also keep the track of all operations performed by certain user
throughout the entire login time.

3. Flow Control:
This prevents information from flowing in a way that it reaches unauthorized users.
Channels are the pathways for information to flow implicitly in ways that violate the
privacy policy of a company are called covert channels.

4. Database Security applying Statistical Method:


Statistical database security focuses on the protection of confidential individual values
stored in and used for statistical purposes and used to retrieve the summaries of values
based on categories. They do not permit to retrieve the individual information.

This allows to access the database to get statistical information about the number of
employees in the company but not to access the detailed confidential/ personal information
about specific individual employee.

5. Encryption:
This method is mainly used to protect sensitive data (such as credit card numbers,
OTP numbers) and other sensitive numbers. The data is encoded using some encoding
algorithms.

An unauthorized user who tries to access this encoded data will face difficulty in decoding
it, but authorized users are given decoding keys to decode data.

Approved by Curriculum Development Centre, Nepal


6. Backup and recovery:
Prioritizing data security also requires a plan for how to access your company's and
client's data in the event of system failure, disaster, data corruption, or breach. Doing
regular data backups is an important activity to help with that access.

A data backup entails making a copy of your data and storing it on a separate system or
medium such as a tape, disk, or in the cloud. You can then recover lost data by using your
backup.

Lab Session: 1. DBMS Concept


Perform the following activities in SQL:

1. Install latest DBMS software (MySQL or PostgreSQL or MSSQL or Oracle)

You can download using Pen drive or CD or Internet. If you want to download from
internet you have to use following steps:

STEP 1: Download the latest MySQL from MySQL official website.

Google X • o_

"' - 1·
...

MySOL Downloads- MySOL

MySOL Community Downloads MySOL S.7


t.lySQLcormuwr'- - ~~~- - ~7~
MJSOL-·Conn<c:b1J lnD<~12 - 1686.1i1r. IJl~

-~
MySQL Installer Developer Zone
OOwnl»::(frii'S'II--- ....,_._"'~ ..........
~-&.O . Zl . O.rnol).ld!X!

MySOL Community Server MySOL Workbench


"'-'"""'1"'1'5'11-'""·..0~ ..,.SOO.""""""""B.0.23Sete<:l

Download MvSOl - free - latest version


;; 0 D ~ J i - '·'~ 8

STEP 2: Click on Downloads from MySQL as follows:

~ ,.,.-"::l....,_..,... .......-..o.
MySQL MYSQLCOM ~ DOCUMENTATfON

MvSQLEnte~riseEdition ···········~~~~~-·
Contact Sales
:; 0 ::1
Cl P!l CJ •D ae,M

Appraved by Curriculum Development Centre, Nepal


STEP 3: Click on MySQL Community (GPL) Downloads from MySQL as follows:

Contact Sales MySQLEnterprlse Edltlon

Gt<mi"Y" ..91'll• Joul0


Fr-:•3)1576013 57
ltaly. •3902249~120
UI<:..W207 SSl SU7

MySQL Cluster CGE


MySQlC iu st e rlsarea~dmeopensourtetr~l<la~~~d~lgne<lforfM~illways-<~n<OC(esstodalau~rhlghthroughput
(01\di(lons.

.MySQLclust... Mi~
.l't.ls,~ ln MySQ!.EnlerprtseEdiiiOn

Custonw Oownload • [Se le ctPatd>es& UpdiiiHlilb,P rod uct ~ ilrth)

MySQl.Cornmun~ty(GPl)Do..nk>ads•

;: 0 ~ ' ~ -

STEP 4: Click on MySQL Installer for windows from MySQL:


r • ~ · ~~ ~ ~ ti·::::::::::::::::::::::::::::::::::::::::::::::::::~~~
t- ~ C O I <Hv.mysq~.com~--.w tl a ~;

® MySQL Community Downloads

.MySQLYumReposltory • CAPI(Iibmysqlcllent)
.MySQL APTReposltory
• MySQLSUSERepository .connector/]

. MySQLCommunltyServer • Connector/Node .js


.MySQLCiuster
.MySQL Router .Connector/Python
.MySQLShell • MySQLNativeOrlverforPHP
.MySQLWorkbern:h
• MySQLBenchmarkTool
• My5Ql Installer for Windows .Timezonedescrlptlontables
. MySQLforVIsu~IStl.ldlo • Download Arch~s

:: 0 ~ ) -

STEP 5: After performing above operation on MySQL Installer for windows from
MySQL, click on second option Windows (x86, 32-bit), MSI Installers:

® MySQL Community Downloa ds


< MySQLinstaller

MysQL Installer 8.0.23

~~ngSyUfln:

IMicrosol't'Nindows

Wlnoto.5(-.»-0il ).a.!SIInn.o 1Mr

Wlndows (>IM.U-bii). MSIInlt. ller


, _.........,...,_
I0 Wes.uggestltlatyouusetheMD) cll«~sum•alldGnuPG SignaluresroverlfytheHltegrtlyofthe
pac:k~you-lo.>d.

:: 0 ~ 3 -

Approved by Curriculum Development Centre, Nepal


STEP 6: Now, Click on No thanks, just start my download.

STEP 7: Now download starts as follows:


MySQllnstalle:r- Community

........ ~====~1 ~

STEP 8: After downloading a file, it shows as follows and then choose Custom:

STEP 9: After choosing Custom, click on first file of MySQL Server 8.0.21 and use
arrow (===>).Similarly, first file of MySQL Workbench 8.0.21 and MySQL Shel18.0.21.
Now, after selection of first file of each, click on Next.

STEP 10: Execute the files for downloading.

lnstaU.uon
. ...
STEP 11: When downloads is completed or after installation it shows as follows:
, ;

-- --

STEP12: Clicking Next, MySQL asks for product configuration that is for configuration
of MySQL Server 8.0.21 as follows and again press Next:

STEP 13: MySQL asks for High Availability, simply click on Next:

STEP 14: Authentication method page appears, simply click on Next:

STEP 15: Then Type and Networking page appears which shows ports and
connectivity, simply, click on Next.

STEP 16: Now, after that Accounts and Roles page appears in which asks to enter
MySQL Reset Password and Repeat Password. After entering password, click on
Next. Remember this password is used when you want to open MySQL using root
login.

Appraved by Curriculum Development Centre, Nepal


STEP 17: After entering password, MySQL shows windows service as follows and
then press Next.

STEP 18: Now Apply Configuration windows opens, simply click on Execute button.

STEP 19: After Configuration process, click on Finish button as follows:

STEP 20: After MySQL installation, installation complete screen appears as follows
and again click on Finish button.

2. Work with CREATE, DROP, ALTER DDL SQL statement

After installation of MySQL, now you are going to learn how to create database and
table. And, then uses of create, drop, alter DDL SQL statement.

Firstly, open MySQL software as follows:

STEP 1: Click on Start button.

STEP 2: Then choose MySQL -> MySQL Workbench 8.0 CE.

STEP 3: Then it shows screen as follows which is home page of MySQL:


MySQL Workbench is the official graphical user interface (G UI) tool for MySQL It allows you to design,
create and browse your database schemas, work with database objects and insert data as well as
design and run SQL queries to work with stored data. You can also migrate schemas and data from other
database vendors to your MySQL database.

Browse DoaJmentation > Read the Blog > Disruss on the Forums >

MySQL Connections G>@ ~I

Local instance MySQL80


J.root
"f" loc~lhoU : 3306

Approved by Curriculum Development Centre, Nepal


STEP 5: In this screen, you can see MySQL local connection. Now you can create
another connection, by simply pressing + symbol and write another connection
name as follows and click on OK.
- 0 X

~~~~~~~================3' ~·~bft~
O:md:lnNtfw:lll l suadn(TCPft') ..,, ...._. . . . .COI'NICt .... JI:DM

~· A6wad
;, - ""Jw""'.o.~""""•-----,l ""' l"" I;';';!..-"'"-,_....,
li _ ,~c:...._ _ _ _ _ _ _ _ __, "-ofhwwiDoornect•

,..,..;; l s.nwa ... l~ :!:':",_,.;.v.tbrt,..,...;•tn


1 -.- 1,....------------,1 ll:.'::.:::.- - -
li

i
~ ---· ·
STEP 6: Now home page should be as follows:

Welcome to MySQL Workbench


M,sQI.~illheofiO.tgr~.-~(CUIIOOifotMoJSQI..It...,)'CIUIOdftlgn.
o:r.-n~,-~~-'o'"""dtWl»>colljl<bAI"'-'t4-..MwtiM
dftlrn,...SOl~to-'<wkloiWfddlu.YouCift*-'...,.*sd'lt!Niand~lr'OI'!I-.
~~IO)OII'MySQl~

-
Now try to observe differences between previous and current home
page.

Creation of database in MySQL (Create command)


STEP 1: Firstly, click on any of these two connections like Local instance MySQLBO:
. ·-.. . . ...
. . . ..____ ____. . . .
Welcome to MySQL Workbench
__________
....,.sca-r.--.
_..
-------------------
....,
--~--....,.soo..·-,...,

---
......,_
... -~-

Approved by Curriculum Development Centre, Nepal


STEP 2: Then it asks for the password which you have typed at the time of MySQL
installation:
;:J ~· 0 • llln<wiCompolot>W<yMo6o]-WO«< 7 tJl - I! X
I HOM( INS.(IIT DESIGNSig.onA
PAGI:LA.VOOT R(f[R(NCES

~~.~~~~~------~~====~----------------~====5· :~~
.
MySQL Connections 0<51

LocalinstanceMySQl80 Mydatabase

., ··~S......

STEP 3: After typing password, the screen appeared as follows:


Ql 9 .,. (!I'

.. ><OME IN5{IIT OCSIGN PAGElAVOVT WERlNCES

~-. · -~---~~
• MySO..Wort"""'h
.

S> &l!ii0il8llli3 Iii


~
J)
SQl-
.. .
[] []

• s ¥ ~AO iiS OO"'~m..,to~ •l(jfir l "-'"


o ............. I
J.c•...,,.............,, Automatlccontexthe lpisd isa bled.Use the toolbartomanuallyget
...................,
·--
.~. he lpforlheOnTenlcarelpositionorlologgleautomatichell'.
..-su..... .... m,.. v.,_,
,!. o.<ot-t!t...

. . . . ..
II S<o~

, .,._,,
.. ,SO'o,.<._.,
(
..,
o ............
4rl ....... _.. ••.,.....
1/' ............. ,..... $«. .

""""'

Remember: To close SQL Additions, use last right upper corner box, which is shown red
in the above picture and then screen appears as below:

® [] ..[]

0s<....,•SIO!u<
2.CtiontCoMUiiont
.l.uw< and.._I'C,
liliJ Statu<"""~" '"V<>r,.bl<<
.!;ootobpo<l
,!.o.taU•po<IJilonor<

IHS'TANCf0
0 Startup /Sto.,.d_,

"'""'"""'
/" Optlon<f~<

0Do>hb<Wd

I!J P<rfor"'""""'"""'
~ ......,....,,,s.o.emosttup

Approved by Curriculum Development Centre, Nepal


STEP 4: There are two methods to create database schema or database file:

Before to create database, firstly, you have to know data types which are as follows:

Data type
A data type specifies a particular type of data, such as integer, floating-point, Boolean etc.

A data type also specifies the possible values for that type, the operations that can be
performed on that type and the way the values of that type are stored.

Different Data Types in SQL


• INT - It is used for whole numbers.
• Decimal (m, n) - It is used to show exact value. It stores m digit value up to n decimal
places.
• VARCHAR (n) - It is for n length of string.
• DATE- DATE statement is to display date. The default format is 'YYYY-MM-DD'.
• TIME - TIME statement is for TIME format. The default format is 'HH:MM:SS'.
• TIMESTAMP- It shows 'YYYY-MM-DD HH:MM:SS'.
Method 1: Click on icon shown in red circle below that is create a new schema in the
connected server.
. MySQL w""'"'.h - --- - D X I
A Loealil'l$1llr'Q!MySQL80 X

·~;; ;- ~"iD;; ~~ ';· """'" ,., ® 1[]1;1[]


1II.@·!!· '&i 8 I ¥ fl ~0 1&1 18 0 riJ i tinttolOOOrows
OstrvtrSiitus
.fctitntConntctiom
.1. Ustrsandl'ri'rilton
8 StatusandSydtmllariablts
Q Data Export
~ DalalmportJRntort

INSTANC£"
0 Startup / Shutdown
A"""-"'"
; Optionsfilt

Coas hboard
drJ P.rfonnanctRtporu
Goo PtrfonnllnttSthtmaSttup

AdminiStroltion Sd'lemu

lnformlltion

No object seected

After that it asks for Name as follows and click Apply.

Appraved by Curriculum Development Centre, Nepal


.MySQI.Wortbench 0
A -. x
File &it v- Query Dacabase Setver Tools Sc:ripting Help

® I []~[]

0StrHtSiatus
J. OlcntConntdlont
.l.usmandPrl¥iltgts
IIIStltus andSysltmVIriablts
Q O•laExport
~ Oltatmport/Rtstort

INSTANCE a
0 StartupfShutdown
.6,StrHtlogs
;optlonsfilt

Ooashboard
~ PtrformanctRtports
t'-Ptrforman<tSd'ltrMSttup

No object selected

Then following menu appears and click on Apply and Finish.

By clicking SCHEMAS, we can see the database:

Method II:
The CREATE DATABASE statement is used to create a new database in SQL.

Syntax:
create database 'database name';

Example:
create database 'gamel' ;

Approved by Curriculum Development Centre, Nepal


you can create database file using query and then click on execute icon
which is shown by using red circle.
Remember:

• You use database name within single quote like 'gamel' and it must be followed by;
(semicolon).
• You can see action output looking down which displays two types of color symbols:
green and red. Green color symbol for successful and red color symbol for error .

·-· Mysa.W~h

® 11]\;;I[J

Q.
·~~==:::J
~cbjects
·
I

1
H I ¥~ P-o 11i 1e OIIJ I !Onttolcm .....
~r10ate .._hbau ·a...,1' 1
· 1 ~ 1 ::'!1! ~I))~
.. IJ co!lege
~ II compote<
• 1!1 9-

.. .
.. .
··-
'i!Tobla

'i!llStoredProced .....
'IIIFvnct!ons
g .... u
. <hool
.. lll sct.ooli
• II ~

0 313;00;$1 """"cfton9ootood>ool
0 413:01:30 CREATESCHEMA'ochooll'

ObjectWo

==
Session
0
0
0
0
5 13:0b45 CREATESCHENA'oct.oc11'
613:021/CREATESCHENA'~·

71l:22:27CREATE-·~·

113:23:16 autedal.,_"g.omel'

o ' ~ m ._ '
1-to)ollec:ted
1 -tl)aflec:tOid
1 --)a'lected

~!I .. ~
I
- ~---

Creation of table in MySQL (Create command)


The CREATE TABLE statement is used to create a new table in a database.

Syntax:
CREATE TABLE table_name (
columnl datatype,
column2 datatype,
column3 datatype,

);
where, columnl, columnl, column3 ..... are columns of the table and data types are int, varchar,
decimal, time, date.
Example,
CREATE TABLE student (
roll int,
first_name varchar(20),

Approved by Curriculum Development Centre, Nepal


last_name varchar(20),
age int
);
By typing same query in database and pressing execute it shows as follows:

®[]~

I~
.. , ..- 1
·,1gl'!.·~B:1·=~~N~~ ~-·~-
4 lut_n_ ~ot'Cha<(M) ,

~' '"!!'-~== : )J OJO!nt

lll~t<>«<~"""o<l-

"-
• l •<t>od
~ I •ct>ooU

··~

Ol>fed.Wo Soslion

I I PTypeheretoo;eafch

DROP statement (Removing of database in MySQL)


The DROP DATABASE statement is used to drop an existing SQL database.

Syntax:
DROP DATABASE 'database name';
Example,
DROP DATABASE 'gamel';

.
,. .,.._.
MySQI.WO<tbtt><h

® [] ..[]

• I~
-~--
~==::J
.. I ~ 9 ~~.~.?-.~~·~ 0 ~ tn11o iCOl_, • ~ ,.r 0. !I)~
• Iii co~
• !J coft!P""'

·-..
.. . g"7ableo

.. ....·-
• l o-1
fl! 9:ottdl'r<><t<lut ..

""'
,.

-"-- -
"-'-
~1l:OUOCREATISOI~·-··

0
a
51l.OUSCRE.\TtSOIEM.\ "od•>oU
61l.02:27CREATISOIEM.\ "_ .
?1322.V CREATE-·-·
8 13:23:1 6 . , . . . - · -·· I

Appraved by Curriculum Development Centre, Nepal


DROP statement (Removing of table in MySQL)
The DROP TABLE statement is used to drop an existing table from SQL database.

Syntax:
DROP TABLE table_name;
Example,
DROP TABLE student;

® []""[I

,·~
...~-.:::==::j.. j a.. ~ ~ ~...~ <~~ 0 0 ~ linloolCOO- • ~ 4 ~ ~
~ II <Ohgc

. ...,._,__
~ • ··­

··-
·-
··-
·-odPfo<odur..

··-
~ :J od>ooiL

0 1 01.12.4') . . . . , , _ _ .

Cl 2011•0!1 ..... . - -

--
I I PTypeheretOseillch

ALTER statement
The ALTER TABLE statement is used to add, delete, modify or change data types of
columns in an existing table.

1. ALTER TABLE- ADD Column

The ALTER TABLE statement is used to add a column to an existing table from SQL
database.

Syntax:
ALTER TABLE table_name
ADD column_name datatype;
Example,
ALTER TABLE student
ADD DateOfBirth date;

Approved by Curriculum Development Centre, Nepal


. .,...,..,
. MySQ.W~h

"'
....
&I Q I ¥ ~i\0 1 &1 1 00~ 1 u.ctol!Dhows · I ~ I ~~(J)@]
0 []""[]

Q, lftlerob)ects 10 A.l.TUT.llt.f student


~ {j «>llov•

~ !'I g ....
. . .. ,_
~ II <OIIIPiillet

., __
... 8 ...- 1

.,_ ~ ··tud...t
.storedPro<edurn

~ ~~ ·­
~ lil •dlooll
~ II ,,,

o_.JolleaedRecoo:to:O ~eo : ow-...: o

Ob)e<l;ltlfo Sesslct1

2. ALTER TABLE- DROP COLUMN

The ALTER TABLE statement is used to delete a column to an existing table from
SQL database.

Syntax:
ALTER TABLE table_name
DROP COLUMN column_name;
Example,
ALTER TABLE student

. . _,
DROP COLUMN age;
MySO._WO<tbotw:h

~;;,::::===::::]
"' • s t ~A o ti e O fl! l ~..atoum"""' • ~ .. Gl. Ill @I
<l ~cb)Kio I 1 0 clr-optoblestude<otJ
~ II «>~<v•

..._
~ II «>OIPIIII«
~ " g-
... 11 'l!rll>l
..-· ..

·-·
li!JstoredPro<ed"OJ

~~ ·II ·­
~ II odlooll
'''

-, __
0
o
1 011:1U9 - - - ·
2011:1"-m•--
0--
S...Coo:lo : 1C£1 . Y""_""'_~,...SOI..,.._ : _Iho_Ol\ol_...IO ". O.OlS-

3. ALTER TABLE- MODIFY COLUMN

The ALTER TABLE statement is used to modify or edit a column data type to an
existing table from SQL database.

Approved by Curriculum Development Centre, Nepal


Syntax:
ALTER TABLE table_name
MODIFY COLUMN column_name datatype;
Example,
ALTER TABLE student
MODIFY COLUMN DateOfBirth year;
Notice that the "DateOfBirth" column is now of type year and is going to hold a year in a two-
or four-digit format.

. MySQI.Workbmth

A ~·"

® 1]1;;1[1

· ~IFtlw~_,~.==:::JI 1 •
• lil collegt
l> lil corrc>l,(er
I> fill
g.,...
• ll oamc:t
• •robles
• • student
ljlpv;.-
IJ!Stor~Proced .....
• "-tions
... . . dloal

. . .. .,.
~> ll sdlool!

Columns: 0 1 O'l08.51 Al.TERTAIIt.EIIIderlmodfyOOLUNNdol«iirii)'NI' O....... )llffededAeconkO~eo · OWarTW90


rol i'lt
frst.._name v.ndlar( 20)
tist._113me y;udl;~r( 2 1l)
d<~teofbi'th ye<tr

ObjKIWo S..Sslon

OwryCompldod

• P Typeheretosearch
'""

Work with SELECT, INSERT, UPDATE, DELETE DDL SQL statement


INSERT Statement
The INSERT statement is used to add new records to an existing table from SQL database.

Syntax:
INSERT INTO table_name (columnl, column2, column3, ... ) VALUES (valuel, value2,
value3, ...);
where, columnl, column2, coumn3 ...... are fields and valul,value2,value3 ...... are string, number
or date/time.

Example,
INSERT INTO student (roll, first_name, last_name, DateOfBirth) VALUES (1, 'Aayushi',
'Karn',2010);

Appraved by Curriculum Development Centre, Nepal


SELEcr Statement
1. The SELECT statement is used to select data from a database. It is used to select from
one or more tables. The data returned is stored in a result table, called the result-set.
Syntax:
SELECT column_name(s) FROM table_name;
Example:
a) SELECT roll FROM student;
It will display all roll numbers inserted in a table student.
b) SELECT* FROM student;
we can use the * character to select ALL columns from a table:
It will display all records from a table student.
2. MySQL Where Clause
The WHERE clause is used to filter records. The WHERE clause is used to extract
only those records that fulfill a specified condition.
Syntax:
SELECT column_name(s) FROM table_name WHERE column_name operator value;
Example:
SELECT roll FROM student WHERE roll = 20;
It will display those records from a table student whose roll number is 20.
3. Select and Order Data From a MySQL Database
The ORDER BY clause is used to sort the result-set in ascending or descending order.
The ORDER BY clause sorts the records in ascending order by default. To sort the
records in descending order, use the DESC keyword.
Syntax:
SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASCI DESC;
Example:
SELECT roll, first_name, last_name FROM student ORDER BY roll ASC;
Update Statement
The UPDATE statement is used to update existing records in a table.
Syntax:
UPDATE table_name
SET columnl =value, column2=value2, ...
WHERE columnName =value
where columnName is columnl, culumn2, ....... and value is text or number or date/time.

Approved by Curriculum Development Centre, Nepal


Example:
UPDATE student
SET first_name = 'Alok',last_name ='Kumar'
WHERE roll = l;
Notice the WHERE clause in the UPDATE syntax: The WHERE clause specifies which
record or records that should be updated. If you omit the WHERE clause, all records will
be updated!
Delete Statement
The DELETE statement is used to delete records from a table:
Syntax:
DELETE from table_name
WHERE columnName =value
where columnName is columnl, culumn2, ....... and value is text or number or date/
time.
Example:
DELETE from student
WHERE DateOfBirth > '2000';

Notice the WHERE clause in the DELETE syntax: The WHERE clause specifies which
record or records that should be deleted. If you omit the WHERE clause, all records will
be deleted!

Practical Session (Lab Exercises 1)


1. Write a SQL statement to create a simple table countries including columns country_
id,country_name and continent.
2. Write a SQL statement to create a simple table student including columns roll,full_
name, DateOfBirth and age.
3. Write a SQL statement to insert some values in a table countries.
4. Write a SQL statement to insert some values in a table student.
5. Write a SQL statement to create a table named jobs including columns job_id, job_
title, min_salary, max_salary and check whether the max_salary amount exceeding
the upper limit 25000.
6. Write a SQL statement to create a table named countries including columns country_
id, country_name and continent and display those countries which are lie in continent
'Asia'.
7. Write a SQL statement to create a table named job_histry including columns
employee_id, start_date, end_date, job_id and department_id and make sure that the
value against column end_date will be entered at the time of insertion to the format
like '--I--I----'.

Approved by Curriculum Development Centre, Nepal


Practical Session (Lab Exercises 2)
1. Write the SQL queries using Data Definition Language (DDL) statements: I
a) Create database mydatabase
b) CREARE TABLE student_detail (student roll number (int) (primary key), student
name (varchar), student address (varchar), student dab (date and time)).
c) CREARE TABLE student_marksheet (student roll number (int) (primary key),
student total marks (int), student division (varchar)).
d) Create a table employee with emp number(int) (primary key), emp name(varchar),
emp dob(date and time), emp address(varchar), empdept(varchar), empsal int.
e) Create a table empdept with Emp number (int) (primary key), dept name(char),
empworkingyear(int)
f) Modify the table student_mark sheet using the alter command and add another filed
grade(varchar)
g) Remove the table empdept using drop command

Practical Session Lab Exercise 3


1. Write the SQL queries using Data Manipulation Language (DML) statements
a) Insert values into student table with field names using insert command.
You have to add 4 to 5 records in a table student_deatail, student_marksheet,
employee
b) Display the table student using select command
You display all records from above table: student_detail, student_marksheet,
employee
c) Update student address in student_detail table using update command.
d) Update student total marks in student_marksheet table using update command.
e) Update student date of birth in employee table using update command.
f) Delete a row from student_detail, student_marksheet and employee tables.

Project Work on DBMS Software


Prepare a list of field and data type for
a) Result processing
b) Preparation of bill
c) Library System
d) Hospital Management System
e) Bill of super market
Use create, insert, update and delete DDL statements to make above project report.

Approved by Curriculum Development Centre, Nepal


- KEYWORDS
• Data: Data is defined as the raw facts and figures.
• Information: When data are processed using a database program or software, they are
converted to the meaningful result, called information.
• Record: A row in a table is called record and it contains information about person, event
etc. Another name of record is tuple.
• Field: A column in a table is called field and it contains specific piece of information
within a record.
• Database: Database is a collection of related information about a subject organized in
a useful manner that provides a base or foundation for procedure, such as retrieving
information, drawing conclusion and make decision.
• DBMS: A DBMS is a set of programs that manages the database files. It allows accessing
the files, updating the records and retrieving data as requested.
• RDBMS: The database system which stores and displays data in tabular format of rows
and columns, like spreadsheet, is known as Relational Database Management System
(RDBMS).
• Primary key: The field or fields that contain the unique value can be set as primary key.
• Normalization: Database normalization is the process of organizing the fields and tables
of a relational database to minimize redundancy and dependency.
• Centralized Database: They are located on a particular (central) location and peripherals
are connected with it to storing and retrieving data as requirement.
• Distributed Database: It is a collection of multiple logically interrelated databases which
are distributed in many geographical locations.

Approved by Curriculum Development Centre, Nepal


EXERCISE
A. Multiple Choice Questions (Tick the best options)
1. A relational database consists of a collection of
a) Tables b) Fields
c) Records d) Keys
2. The term is used to refer to a row.
a) Attribute b) Tuple
c) Field d) Instance
3. The term attribute refers to a of a table.
a) Record b) Column
c) Tuple d) Key
4. CREATE TABLE employee (name VARCHAR, id INTEGER What type of statement is this?
a) DML b) DDL
c) View d) Integrity constraint
5. In the given query which of the keyword has to be inserted?
INSERT INTO employee _ _ (4,Alok,2000);
a) Table b) Values
c) Relation d) Field
6. In the _ _ _ _ normal form, a composite attribute is converted to individual attributes.
a) First b) Second
c) Third d) Fourth
7. With SQL, how do you select all the records from a table named "Persons" where the value
of the column "FirstName" ends with an "a"?
a) SELECT * FROM Persons WHERE FirstName='a'
b) SELECT* FROM Persons WHERE FirstName LIKE 'a%'
c) SELECT* FROM Persons WHERE FirstName LIKE '%a'
d) SELECT * FROM Persons WHERE FirstName='%a%'

I
8. The UPDATE SQL clause can _ _ _ __
a) update only one row at a time
b) update more than one row at a time
c) delete more than one row at a time
d) delete only one row at a time

Approved by Curriculum Development Centre, Nepal


9. Which SQL keyword is used to retrieve a maximum value?
a] MOST b) TOP
c) MAX d) UPPER
10. Which of the following is not a DDL command?
a] UPDATE b) TRUNCATE
c) ALTER d) None of the Mentioned

Ans: 1{a) 2{b) 3{b) 4{b) 5{b) 6{a) 7{c) B{b) 9{c) 10{a)

B. Short Answer Questions:


1. Differentiate between Database and DBMS. Explain the top-down methodology of Database
design.
2. Explain the benefits of centralized database system.
3. Write advantages and disadvantages of DBMS.
4. Define primary key, candidate key and alternate key. Write the importance of primary key
with suitable example.
5. Explain DDL and DML with some common commands
6. Differentiate between centralized and distributed database system.
7. Write short notes on the following:
a) Data and information b) Field and record
c) Data Dictionary d) DDL
e) DML f) Primary key
g) Relationship

C. Long Answer Questions:


1. Explain different database models with merits and demerits.
2. What is normalization? Explain normalization process with examples.
3. What is database security? Why is it important? Describe different methods to protect
database of an organization.

CASE STUDY
Make a report that should consists of all DDL and DML commands along with function,
syntax and example.

Approved by Curriculum Development Centre, Nepal


ORACLE Oracle Corporation is an American multinational
I
computer technology corporation headquartered in
Redwood City, California, The United States. The
company specializes in developing and marketing
computer hardware systems and enterprise software
products - particularly its own brands of database
management systems. It is the third-largest software
maker by revenue, after Microsoft and IBM.

Lawrence Joseph "Larry" Ellison, a co-founder


of Oracle Corporation, has served as Oracle's CEO
throughout its history. He is an American co-founder
and chief executive of Oracle Corporation, an
enterprise software company. As of 2012, he was the
third-wealthiest American with an estimated worth of
$41 billion including his ownership of Oracle company
stock.
I
\'\ r
~. \ MySQL is (as of 2008) the world's most widely used open
MySQL., source relational database management system (RDBMS)
that runs as a server providing multi-user access to a number
of databases. It is named after co-founder Michael Widen ius'
daughter, My. The SQL phrase stands for Structured Query
Language.

MySQL is a popular choice of database for use in web


applications, and is a central component of the widely used
LAMP open source web application software stack (and
other 'AMP' stacks). LAMP is an acronym for "Linux, Apache,
MySQL, Peri/PHP/Python." Free-software-open source
projects that require a full-featured database management
system often use MySQL.

For commercial use, several paid editions are available, and


offer additional functionality. Applications which use MySQL
databases include: TYP03, Joomla, WordPress, phpBB,
MyBB, Drupal and other software. MySQL is also used in
many high-profile, large-scale World Wide Web products,
including Wikipedia, Google (though not for searches),
Facebook, Twitter, Flickr, Nokia.com, and YouTube.

Approved by Curriculum Development Centre, Nepal


At the end of this unit, students will be able to
:> define networking with its purpose and
communication
:> understand the basic concept of analog signal,
digital signal and direction of communication
flow
:> understand types of networks based on
architecture and geographical area
:> understand different types of LAN topologies
:> know about different types of transmission media
:> know about different network connecting devices
:> understand the basic concept of OSI reference
model and some papular protocols
:> recognize communication media and connecting
devices

:> For teaching this unit, we are assigned


approximate fifteen theory classes and fifteen
practical classes
:> Let the students understand the basic concept of
networking with its purpose and communication
with the help of real life examples
:> Let the students understand the basic concept
of analog signal, digital signal and direction
of communication flow with the help of real life
examples and diagrams
:> Let the students understand types of networks
based on architecture (peer-to-peer and client/
seroer) and geographical area(LAN, MAN and
WAN) with the help of real life examples and
diagrams
:> Let the students understand different types LAN
tvpologies(Bus, Star, Ring, Tree, Mesh)with the
help of examples and diagrams
:> Let the students know about different types of
transmission media(Coaxial cable, Twisted Pair
Cable, Optical Fibre Cable, Satellite, Radio Wave,
Microwave)by visualizing
:> Let the students know about different network
connecting devices (Modem, NIC, Switch/ HUB,
Router, Gateway, Repeater, Bluetooth, IR, WiFi)
by visualizing
:> Let the students understand the basic concept
of OSI reference model with different layers and
some papular protocols(TCP/IP, SMTP, POP3,
FTP, HTTP, Telnet)
:> Lastly, Let the students recognize communication
media and connecting devices by visualizing
2.1 Basic Elements of Communication System
The history of communication started from telegraphy in early 1840s. After that, radio
communication made easier during the time period of wars. After all, the use of copper
cable, optical fiber and satellite has made communication faster, reliable and secured.
Various forms of data such as text, number, audio, video etc. can be transmitted from one
place to another place. Telephone, Television, Radio and Internet are very popular and
widely used as means of communication.

Communication and networking are changing the way of our life, businesses and services.
Communication refers to the exchange of information between sender and receiver with
the help of electronic means of communication. The electronic means of communication
may be wires, radio or satellite. The communication can be local or remote. The local
communication occurs face to face whereas the remote communication occurs over
distance.
POINTS TO REMEMBER

I
Communication is defined as the exchange of electronic form of
information between sender and receiver devices with the help of means
of communication

Rule 1 Rule 1
Rule 2 Rule 2

RuleN RuleN

( Sender )t-----------1( Receiver )

Figure 2.1: Components of communication system

A communication system has five major basic components/ elements: message, sender,
receiver, transmission medium and protocol as shown in the figure below:
Message: The message is data or information to be communicated and it is in the form of
text, number, picture, audio and video.
Sender: The sender device sends the messages to the receiver and it can be computer,
workstation or any networking devices.
Receiver: The receiver device receives the messages from the medium and it can be
computer, workstation or any networking devices.
Transmission Medium: The transmission medium is physical connection in which a
message can travel from sender to receiver and vice versa. The medium can be wired or
wireless.

Approved by Curriculum Development Centre, Nepal


Protocols: A protocol is a set of common
rules that manages the data communication.
Without protocol two devices can be
connected but not be communicated. It
represents an agreement among the different
communication devices in a network.
Networking is the process of interconnecting
two or more peoples or objects in a network.
The object may be people, organizations,
radio stations, computers, animals etc.
Various types of networks available in the
world are: human networks, telephone Figure 2.2: Computer Network
networks, radio networks, computer
networks, etc.
Computer network has brought a revolution in the world of information technology.
So it has been the backbone of most of the big or small enterprises. It is being used to
provide resource sharing among the systems from few feet to thousand of kilometres. It
also allows the people to access information from the remote computer. Moreover it also
links faxes, printers, photocopy machine and different network devices.
Computer network is the interconnection of two or more network devices with the
help of transmission media and set of rules. The transmission media help us to transfer
information from one computer to another computer and a set of protocols that defines
the common rules for data transmission among the various types of network devices.
POINTS TO REMEMBER

I
Computer network is defined as the interconnection of two or more
computers or networking devices with the help of transmission media and
set of protocols

Purpose of Networking (Advantages)


1. Sharing Resources: Hardware resources such as processor, storage devices, printers,
scanner, etc can be shared among us using computer network. It helps to minimize the
operational cost of an organization. Similarly software can be shared among us within a
network. It is possible to share data or information among multiple users at the same time.
2. Faster and Cheaper Communication: Communication in modem days has become
very faster and cheaper to send information to a long distance through network. We
can send letters, attach files, perform voice chat and video conference with almost
free of cost with the help of network.
3. Centralized Control: All network resources such as computers, printers, file,
database, etc can be managed and controlled by a central connecting computer also
known as the server. So, any rules, privileges, security measures that are necessary in

Approved by Curriculum Development Centre, Nepal

You might also like