You are on page 1of 146

Software Design

CPE 223L
Software design
• Software design is the process by which an agent
creates a specification of a software artifact
intended to accomplish goals, using a set of
primitive components and subject to constraints.
VB.Net
• Visual Basic .NET (VB.NET) is an object-oriented
computer programming language implemented
on the .NET Framework.
• Like all other .NET languages, VB.NET has
complete support for object-oriented concepts.
Everything in VB.NET is an object, including all of
the primitive types (Short, Integer, Long, String,
Boolean, etc.) and user-defined types, events, and
even assemblies. All objects inherits from the
base class Object.
Basic Syntax
• Object − Objects have states and behaviors. An object is an
instance of a class.
• Class − A class can be defined as a template/blueprint that
describes the behaviors/states that objects of its type
support.
• Methods − A method is basically a behavior. A class can
contain many methods. It is in methods where the logics are
written, data is manipulated and all the actions are executed.
• Instance Variables − Each object has its unique set of
instance variables. An object's state is created by the values
assigned to these instance variables.
Identifiers
• An identifier is a name used to identify a class,
variable, function, or any other user-defined item.
The basic rules for naming classes in VB.Net are
as follows −
• A name must begin with a letter that could be followed
by a sequence of letters, digits (0 - 9) or underscore.
The first character in an identifier cannot be a digit.
• It must not contain any embedded space or symbol
like ? - +! @ # % ^ & * ( ) [ ] { } . ; : " ' / and \. However,
an underscore ( _ ) can be used.
• It should not be a reserved keyword.
Data Types
• It refers to an extensive system used for declaring
variables or functions of different types. The type
of a variable determines how much space it
occupies in storage and how the bit pattern
stored is interpreted.
Data Types
Boolean Byte Char
Date Decimal Double
Integer Long Object
Sbyte Short Single
String Uinteger Ulong
UShort
The Type Conversion Functions in
VB.Net
• CBool(expression) - Converts the expression to
Boolean data type.
• CByte(expression) - Converts the expression to
Byte data type.
• CChar(expression) - Converts the expression to
Char data type.
• CDate(expression) - Converts the expression to
Date data type
The Type Conversion Functions in
VB.Net
• CDbl(expression) - Converts the expression to
Double data type.
• CDec(expression) - Converts the expression to
Decimal data type.
• CInt(expression) - Converts the expression to
Integer data type.
• CLng(expression) - Converts the expression to
Long data type.
Variables
• A variable is nothing but a name given to a
storage area that our programs can manipulate.
Each variable in VB.Net has a specific type, which
determines the size and layout of the variable's
memory; the range of values that can be stored
within that memory; and the set of operations
that can be applied to the variable.
Variables
Type Example
Integral types SByte, Byte, Short, UShort,
Integer, UInteger, Long,
ULong and Char
Floating point types Single and Double
Decimal types Decimal
Boolean types True or False values, as
assigned
Date types Date
Variable Declaration
• The Dim statement is used for variable
declaration and storage allocation for one or
more variables. The Dim statement is used at
module, class, structure, procedure or block level.
Variable Declaration
• Syntax for variable declaration in VB.Net is −
[ < attributelist > ] [ accessmodifier ] [[ Shared ]
[ Shadows ] | [ Static ]] [ ReadOnly ] Dim
[ WithEvents ] variablelist
Variable Declaration
• attributelist is a list of attributes that apply to the variable. Optional.
• accessmodifier defines the access levels of the variables, it has values as -
Public, Protected, Friend, Protected Friend and Private. Optional.
• Shared declares a shared variable, which is not associated with any specific
instance of a class or structure, rather available to all the instances of the class
or structure. Optional.
• Shadows indicate that the variable re-declares and hides an identically named
element, or set of overloaded elements, in a base class. Optional.
• Static indicates that the variable will retain its value, even when the after
termination of the procedure in which it is declared. Optional.
• ReadOnly means the variable can be read, but not written. Optional.
• WithEvents specifies that the variable is used to respond to events raised by
the instance assigned to the variable. Optional.
• Variablelist provides the list of variables declared.
Variable Declaration
• Each variable in the variable list has the following
syntax and parts −
• variablename − is the name of the variable
• boundslist − optional. It provides list of bounds of each
dimension of an array variable.
• New − optional. It creates a new instance of the class when
the Dim statement runs.
• datatype − Required if Option Strict is On. It specifies the
data type of the variable.
• initializer − Optional if New is not specified. Expression
that is evaluated and assigned to the variable when it is
created.
Variable Declaration Example
• Dim StudentID As Integer
• Dim StudentName As String
• Dim Salary As Double
• Dim count1, count2 As Integer
• Dim status As Boolean
• Dim exitButton As New
System.Windows.Forms.Button
• Dim lastTime, nextTime As Date
Variable Initialization
• Variables are initialized (assigned a value) with an
equal sign followed by a constant expression. The
general form of initialization is −
• variable_name = value;
• Example:
• Dim pi As Double
• pi = 3.14159
• Dim StudentID As Integer = 100
• Dim StudentName As String = "Bill Smith“
Accepting Values from User
• The Console class in the System namespace
provides a function ReadLine for accepting input
from the user and store it into a variable. For
example:
• Dim message As String
• message = Console.ReadLine
Accepting Values from User
Module variablesNdataypes
Sub Main()
Dim message As String
Console.Write("Enter message: ")
message = Console.ReadLine
Console.WriteLine()
Console.WriteLine("Your Message: {0}", message)
Console.ReadLine()
End Sub
End Module
Decision Making
• If...Then statement consists of a boolean
expression followed by one or more statements.
If (a <= 20) Then
c= c+1
End If
Decision Making
• If...Then statement can be followed by an optional Else
statement, which executes when the boolean expression is
false.
If (a < 20) Then
' if condition is true then print the following
Console.WriteLine("a is less than 20")
Else
' if condition is false then print the following
Console.WriteLine("a is not less than 20")
End If
Loops
• Do Loops
Do
Console.WriteLine("value of a: {0}", a)
a=a+1
Loop While (a < 20)
Loops
• For...Next Loop

For a = 10 To 20
Console.WriteLine("value of a: {0}", a)
Next
Loops
• Each...Next Loop
For Each arrayItem In anArray
Console.WriteLine(arrayItem)
Next
Loops
• While... End While Loop
While a < 20
Console.WriteLine("value of a: {0}", a)
a=a+1
End While
Loops
• Exit Statement
While (a < 20)
Console.WriteLine("value of a: {0}", a)
a=a+1
If (a > 15) Then
'terminate the loop using exit statement
Exit While
End If
End While
Loops
• Continue Statement
Do
If (a = 15) Then
' skip the iteration '
a=a+1
Continue Do
End If
Console.WriteLine("value of a: {0}", a)
a=a+1
Loop While (a < 20)
DEVELOPING CLASSES
• One of the primary uses of OOP is to develop
user-defined data types.
• To aid our discussion, and to illustrate some of the
fundamental principles of OOP, we will develop
two classes for describing one or two features of
a geometric data processing system: the Point
class and the Circle class.
Data Members and Constructors
• The data defined in a class, generally, are meant to
stay hidden within the class definition.
• This is part of the principle of encapsulation. The
data stored in a class are called data members, or
alternatively, fields.
• To keep the data in a class hidden, data members
are usually declared with the Private access
modifier.
• Data declared like this cannot be accessed by user
code.
Data Members and Constructors
• The Point class will store two pieces of data—the
x coordinate and the y coordinate. Here are the
declarations for these data members:
Data Members and Constructors
• When a new class object is declared, a constructor
method should be called to perform any initialization
that is necessary.
• Constructors in VB.NET are named New by default,
unlike in other languages where constructor methods
are named the same as the class.
• Constructors can be written with or without arguments.
A constructor with no arguments is called the default
constructor.
• A constructor with arguments is called a parameterized
constructor.
Data Members and Constructors
Property Methods
• A Property method provides the ability to both
set and retrieve the value of a data member
within the same method definition.
• This is accomplished by utilizing a Get clause and
a Set clause.
Property Methods
Other Methods
• Of course, constructor methods and Property
methods aren’t the only methods we will need in
a class definition.
• One method included in all well-defined classes is
a ToString method, which returns the current
state of an object by building a string that consists
of the data member’s values.
Other Methods
• Here’s the ToString method for the Point class:
Other Methods
• Notice that the ToString method includes the
modifier Overrides.
• This modifier is necessary because all classes
inherit from the Object class and this class already
has a ToString method.
• For the compiler to keep the methods straight,
the Overrides modifier indicates that, when the
compiler is working with a Point object, it should
use the Point class definition of ToString and not
the Object class definition.
Other Methods
• One additional method many classes include is
one to test whether two objects of the same class
are equal. Here is the Point class method to test
for equality:
Inheritance and Composition
• The ability to use an existing class as the basis for
one or more new classes is one of the most
powerful features of OOP.
• There are two major ways to use an existing class
in the definition of a new class:
• The new class can be considered a subclass of the
existing class (inheritance).
• The new class can be considered as at least partially
made up of parts of an existing class (composition).
Inheritance and Composition
• For example, we can make a Circle class using a
Point class object to determine the center of the
circle.
• Since all the methods of the Point class are
already defined, we can reuse the code by
declaring the Circle class to be a derived class of
the Point class, which is called the base class.
• A derived class inherits all the code in the base
class plus it can create its own definitions.
Inheritance and Composition
• The Circle class includes both the definition of a
point (x and y coordinates) as well as other data
members and methods that define a circle (such
as the radius and the area). Here is the definition
of the Circle class:
Inheritance and Composition
Inheritance and Composition
Inheritance and Composition
• There are a couple of features in this definition
you haven’t seen before.
• First, the parameterized constructor call includes
the following line:
• This is a call to the constructor for the base class
(the Point class) that matches the parameter list.
• Every derived class constructor must include a call
to one of the base classes’ constructors.
COLLECTIONS DEFINED
• A collection is a structured data type that stores
data and provides operations for adding data to
the collection, removing data from the collection,
updating data in the collection, and setting and
returning the values of different attributes of the
collection.
COLLECTIONS DEFINED
• Collections can be broken down into two types:
• A linear collection is a list of elements where one
element follows the previous element.
• Nonlinear collections hold elements that do not have
positional order within the collection.
COLLECTIONS DESCRIBED
• Linear collections can be either direct access
collections or sequential access collections.
• Whereas nonlinear collections can be either
hierarchical or grouped.
Direct Access Collections
• The most common example of a direct access
collection is the array. We define an array as a
collection of elements with the same data type
that are directly accessed via an integer index.
Direct Access Collections
• Another type of direct access collection is the
string. A string is a collection of characters that
can be accessed based on their index, in the same
manner we access the elements of an array.
• Strings are also implemented as class objects in
VB.NET.
Direct Access Collections
• The final direct access collection type is the
structure, known as a userdefined type in Visual
Basic 6.
• A structure is a composite data type that holds
data that may consist of many different data
types.
Direct Access Collections
• A powerful addition to the VB.NET structure is the
ability to define methods for performing
operations stored on the data in a structure. This
makes a structure quite like a class, though you
can’t inherit from a structure.
Direct Access Collections
Sequential Access Collections
• A sequential access collection is a list that stores
its elements in sequential order. We call this type
of collection a linear list.
• Linear lists are not limited by size when they are
created, meaning they are able to expand and
contract dynamically.
• Items in a linear list are not accessed directly;
they are referenced by their position,
Sequential Access Collections
• A sequential access collection is a list that stores
its elements in sequential order. We call this type
of collection a linear list.
• Linear lists are not limited by size when they are
created, meaning they are able to expand and
contract dynamically.
• Items in a linear list are not accessed directly;
they are referenced by their position,
Sequential Access Collections
• Stack is a list where access is restricted to the
beginning (or top) of the list. Items are placed on
the list at the top and can only be removed from
the top. For this reason, stacks are known as Last-
In, First-Out structures.
Sequential Access Collections
• A queue is a list where items are added at the
rear of the list and removed from the front of the
list.
• This type of list is known as a First-In, First-Out
structure.
Hierarchical Collections
• Nonlinear collections are broken down into two
major groups:
• Hierarchical Collections
• Group Collections.
Hierarchical Collections
• A hierarchical collection is a group of items
divided into levels. An item at one level can have
successor items located at the next lower level.
• One common hierarchical collection is the tree. A
tree collection looks like an upside-down tree,
with one data element as the root and the other
data values hanging below the root as leaves.
Hierarchical Collections
• The file systems of most modern operating
systems are designed as a tree collection, with
one directory as the root and other subdirectories
as children of the root.
Group Collections
• A nonlinear collection of items that are unordered
is called a group. The three major categories of
group collections are sets, graphs, and networks.
• A set is a collection of unordered data values
where each value is unique. The list of students in
a class is an example of a set, as is, of course, the
integers.
• Operations that can be performed on sets include
union and intersection.
Group Collections
THE VB.NET COLLECTION CLASS
• The VB.NET Framework library includes a generic
collection class for storing data. The class includes
two methods and two properties for adding,
removing, retrieving, and determining the
number of items in the collection.
Adding Data to a Collection
• The Add method is used to store data in a
collection. In its simplest form, the method takes
just one argument, a data item to store in the
collection.
Adding Data to a Collection
• Another way to add data to a collection is to also
store keys along with the data.
Adding Data to a Collection
• Collection items are retrieved with the Item
method. Items can be retrieved either by their
index or by a key, if one was specified when the
item was added. Using the index and the Count
property, we can return each item from a
collection using a For loop as follows:
Arrays and ArrayLists
• The array is the most common data structure and
is found in nearly all computer programming
languages.
• A new feature in VB.NET is the ArrayList class. An
ArrayList is an array that grows dynamically as
more space is needed.
ARRAY BASICS
• An array stores a set of elements ordered by
position. The base position, or index, of arrays in
VB.NET is zero.
Declaring and Initializing Arrays
Setting and Accessing Array Elements
• Elements are stored in an array either by direct
access or by calling the Array class method
SetValue.
• Direct access involves referencing an array position by
index on the left-hand side of an assignment statement:

• The SetValue method provides a more object-oriented


way to set the value of an array element.
Setting and Accessing Array Elements
• Array elements are accessed either by direct
access or by calling the GetValue method.
• The GetValue method takes a single argument, called
an index:
Methods and Properties for Retrieving
Array Metadata
• The Array class provides several properties for
retrieving metadata about an array:
• Length: Returns the total number of elements in all
dimensions of an array.
• GetLength: Returns the number of elements in
specified dimension of an array.
• Rank: Returns the number of dimensions of an array.
• GetType: Returns the Type of the current array
instance.
Multidimensional Arrays
• Multidimensional arrays are declared by providing
the upper bound of each of the dimensions of the
array.
DYNAMICALLY RESIZING ARRAYS
• An array is declared (or initialized) with a size, but
this size is not fixed and can vary throughout the
lifetime of the program using the array.
• An array can be dynamically resized using the
ReDim and Preserve commands.
• The ReDim command used by itself automatically resets
all array elements to their default values and resizes the
array to the new upper bound.
DYNAMICALLY RESIZING ARRAYS
• If you want to retain the values in the array, you
have to combine the ReDim command with the
Preserve command:
THE ARRAYLIST CLASS
• Using ReDim and ReDim Preserve consumes
precious computer resources, plus you will have
to add code to your program to test for when you
need to resize. One solution to this problem is to
use a type of array that automatically resizes itself
when the array runs out of storage space.
THE ARRAYLIST CLASS
• An ArrayList object has a Capacity property that
stores its size.
• The initial value of the property is 16. When the
number of elements in an ArrayList reaches this
limit, the Capacity property adds another 16
elements to the storage space of the ArrayList.
Members of the ArrayList Class
• Add(): Adds an element to the ArrayList.
• AddRange(): Adds the elements of a collection to the end of the
ArrayList.
• Capacity: Stores the number of elements the ArrayList can hold.
• Clear(): Removes all elements from the ArrayList.
• Contains(): Determines whether a specified item is in the ArrayList.
• CopyTo(): Copies the ArrayList or a segment of it to an array.
• Count: Returns the number of elements currently in the ArrayList.
• GetEnumerator(): Returns an enumerator to iterate over the ArrayList.
• ToArray(): Copies the elements of the ArrayList to an array.
• TrimToSize(): Sets the capacity of the ArrayList to the number of
elements in the ArrayList.
Members of the ArrayList Class
• GetRange(): Returns a subset of the ArrayList as an ArrayList.
• IndexOf(): Returns the index of the first occurrence of the
specified item.
• Insert(): Inserts an element into the ArrayList at a specified index.
• InsertRange(): Inserts the elements of a collection into the
ArrayList starting at the specified index.
• Item(): Gets or sets an element at the specified index.
• Remove(): Removes the first occurrence of the specified item.
• RemoveAt(): Removes an element at the specified index.
• Reverse(): Reverses the order of the elements in the ArrayList.
• Sort(): Alphabetically sorts the elements in the ArrayList.
Object Oriented Programming in Visual
Basic
• Visual Basic .NET supports all the key OOP features
like Polymorphism, Inheritance, Abstraction and
Encapsulation.
• A major factor in the invention of Object-Oriented
approach is to remove some of the flaws
encountered with the procedural approach.
• In OOP, data is treated as a critical element and does
not allow it to flow freely. It bounds data closely to
the functions that operate on it and protects it from
accidental modification from outside functions.
Some features of Object Oriented
programming are as follows:
• Emphasis on data rather than procedure
• Programs are divided into Objects
• Data is hidden and cannot be accessed by external functions
Objects can communicate with each other through functions
• New data and functions can be easily added whenever
necessary
• Follows bottom-up approach Concepts of OOP:
• Objects
• Classes
• Data Abstraction and Encapsulation
• Inheritance
• Polymorphism
Objects
• Objects are the basic run-time entities in an
object-oriented system.
• Programming problem is analyzed in terms of
objects and nature of communication between
them.
• When a program is executed, objects interact
with each other by sending messages.
• Different objects can also interact with each other
without knowing the details of their data or code.
Classes
• A class is a collection of objects of similar type.
Once a class is defined, any number of objects
can be created which belong to that class.
Constructors
• A constructor is a special member function whose task is to
initialize the objects of it's class.
• This is the first method that is run when an instance of a type
is created.
• A constructor is invoked whenever an object of it's associated
class is created.
• If a class contains a constructor, then an object created by
that class will be initialized automatically.
• We pass data to the constructor by enclosing it in the
parentheses following the class name when creating an
object.
• Constructors can never return a value, and can be overridden
to provide custom initializations functionality.
Destructors
• A destructor, also know as finalizer, is the last method run
by a class.
• Within a destructor we can place code to clean up the
object after it is used, which might include decrementing
counters or releasing resources.
• We use Finalize method in Visual Basic for this and the
Finalize method is called automatically when the .NET
runtime determines that the object is no longer required.
• When working with destructors we need to use the
overrides keyword with Finalize method as we will
override the Finalize method built into the Object class.
Data Abstraction and Encapsulation
• Abstraction refers to the act of representing
essential features without including the
background details or explanations.
• Classes use the concept of abstraction and are
defined as a list of abstract attributes.
• Storing data and functions in a single unit is
encapsulation.
• Data cannot be accessible to the outside world and
only those functions which are stored in the class
can access it.
Inheritance
• Inheritance is the process by which objects can
acquire the properties of objects of other class.
• In OOP, inheritance provides reusability, like,
adding additional features to an existing class
without modifying it.
• This is achieved by deriving a new class from the
existing one.
• The new class will have combined features of
both the classes.
Inheritance
Inheritance
Polymorphism
• Polymorphism means the ability to take more
than one form.
• An operation may exhibit different behaviors in
different instances.
• The behavior depends on the data types used in
the operation.
• Polymorphism is extensively used in
implementing Inheritance.
Polymorphism
• Polymorphism is one of the crucial features of OOP.
It means "one name, multiple forms". It is also called
as Overloading which means the use of same thing
for different purposes.
• Using Polymorphism we can create as many
functions we want with one function name but with
different argument list.
• The function performs different operations based on
the argument list in the function call.
• The exact function to be invoked will be determined
by checking the type and number of arguments in
the function.
Polymorphism
Polymorphism
Abstract Classes
• An abstract class is the one that is not used to create
objects.
• An abstract class is designed to act as a base class (to be
inherited by other classes).
• Abstract class is a design concept in program
development and provides a base upon which other
classes are built.
• Abstract classes are similar to interfaces.
• After declaring an abstract class, it cannot be instantiated
on it's own, it must be inherited.
• Like interfaces, abstract classes can specify members that
must be implemented in inheriting classes.
What Is a Database?

• Database
– A collection of related data stored in a manner that
enables information to be retrieved as needed
• Database Management System (DBMS)
– Used to create, maintain, and access databases
– Database engine
• The part of the program that actually stores and
retrieves data
– Microsoft Access, OpenOffice Base, Corel Paradox, Oracle
Database, etc.

Understanding Computers: Today and Tomorrow, 15th Edition 94


What Is a Database?

• A database typically consists of:


– Tables
• Collection of related records
– Fields (columns)
• Single category of data to be stored in a database
(name, telephone number, etc.)
– Records (rows)
• Collection of related fields in a database (all the fields
for one customer, for example)

Understanding Computers: Today and Tomorrow, 15th Edition 95


What Is a Database?

• A Simple Relational Database Example

Understanding Computers: Today and Tomorrow, 15th Edition 96


What is a Database?

– Primary Key
• Field that uniquely identifies the records in a table
• Field in a table that is used to relate that table to other
tables

Understanding Computers: Today and Tomorrow, 15th Edition 97


What Is a Database?

• Individuals Involved with a Database Management System


– Database Designers
• Design the database
– Database Developers
• Create the database
– Database Programmers
• Write the programs needed to access the database or
tie the database to other programs

Understanding Computers: Today and Tomorrow, 15th Edition 98


What Is a Database?

– Database Administrators
• Responsible for managing the databases within an
organization
– Users
• Individuals who enter data, update data, and retrieve
information from the database

Understanding Computers: Today and Tomorrow, 15th Edition 99


What Is a Database?

• The Evolution of Databases

Understanding Computers: Today and Tomorrow, 15th Edition 10


0
What Is a Database?

• Advantages and Disadvantages of the DBMS Approach


– Advantages
• Low level of redundancy
– Faster response time
– Lower storage requirements
– Easier to secure
– Increased data accuracy
– Disadvantages
• Increased vulnerability (backup is essential)

Understanding Computers: Today and Tomorrow, 15th Edition 10


1
Inside the Industry Box

File Management Systems


– Tables are
not related
so more
time-
consuming
and more
redundancy

Understanding Computers: Today and Tomorrow, 15th Edition 10


2
Data Concepts and Characteristics

• Data Hierarchy
– Fields/columns
• Hold single pieces of data
– Records/rows
• Groups of related fields
– Tables
• Collection of related records
– Database
• Contains a group of related tables

Understanding Computers: Today and Tomorrow, 15th Edition 10


3
Data Concepts and Characteristics

• Entities and Entity Relationships


– Entity
• A person, object, or event of importance to the
organization
• Entities that the organization wants to store data about
typically becomes a database table
– Attributes
• Characteristics of an entity
• Typically become fields in the entity’s database table
– Relationship
• An association between two or more entities
Understanding Computers: Today and Tomorrow, 15th Edition 10
4
Data Concepts and Characteristics

– One to One (1:1) Entity Relationships


• One entity is related to only one other entity of a particular
type
• Not a common type of relationship
– One to Many (O:M) Entity Relationship
• Most common type of relationship
• One entity can be related to more than one other entity
– A supplier can supply more than one product to a
company
– Many to Many (M:M) Entity Relationships
• One entity can be related to more than one other entity, and
those entities can be related to multiple entities of the same
type as the original entity

Understanding Computers: Today and Tomorrow, 15th Edition 10


5
Data Concepts and Characteristics

• Data Definition
– The process of describing the properties of data to be
included in a database table
– During data definition, each field is assigned:
• Name (must be unique within the table)
• Data type (such as Text, Number, Currency, Date/Time)
• Description (optional description of the field)
• Properties (field size, format of the field, allowable
range, if field is required, etc.)
– Finished specifications for a table become the table
structure

Understanding Computers: Today and Tomorrow, 15th Edition 10


6
Data Concepts and Characteristics

Understanding Computers: Today and Tomorrow, 15th Edition 10


7
Data Concepts and Characteristics

• The Data Dictionary


– Contains all data definitions in a database, including:
• Table structures
• Security information (passwords, etc.)
• Relationships between the tables in the database
• Basic information about each table, such as the current
number of records
– Does not contain any of the data in the tables
– Does contain metadata, which is information about the
database tables
– Ensures that data being entered into the database does
not violate any specified criteria
Understanding Computers: Today and Tomorrow, 15th Edition 10
8
Data Integrity, Security, and Privacy

• Data Integrity
– Accuracy of Data
• Quality of data entered determines the quality of
generated information
– Data Validation
• Process of ensuring that data entered into the database
is valid
• Record validation rules
– Checks all fields before changes to a record
are saved
• Can be enforced on a per transaction basis so the entire
transaction will fail if one part is invalid
Understanding Computers: Today and Tomorrow, 15th Edition 10
9
Data Integrity, Security, and Privacy

– Database Locking
• Prevents two individuals from changing the same data
at the same time

Understanding Computers: Today and Tomorrow, 15th Edition 11


0
Data Integrity, Security, and Privacy

• Data Security
– Protects data against destruction and misuse
– Protects against unauthorized access to and unauthorized
use of a database
– Database activity monitoring programs can be used to
detect possible intrusions and risks
– Prevents data loss
– Should include strict backup and disaster-recovery
procedures (disaster-recovery plan)
– Should be used with both in-house and cloud databases

Understanding Computers: Today and Tomorrow, 15th Edition 11


1
Data Integrity, Security, and Privacy

Understanding Computers: Today and Tomorrow, 15th Edition 11


2
Data Integrity, Security, and Privacy

– Data Privacy
• Growing concern because of the vast amounts of
personal data stored in databases today
• Many states require businesses to notify customers
when their personal data has been compromised
• Data breaches can be costly
– One estimate is $200 per breached record

Understanding Computers: Today and Tomorrow, 15th Edition 11


3
Data Organization

• Data Organization
– Arranging data for efficient retrieval
– Indexed organization
• Uses an index to keep track of where data is stored in a
database
• Direct Organization
– Uses hashing algorithms to specify the exact storage
location
– Algorithms should be
designed to limit collisions
– Some systems use a combination of both
indexed and direct organization
Understanding Computers: Today and Tomorrow, 15th Edition 11
4
Data Organization

Understanding Computers: Today and Tomorrow, 15th Edition 11


5
Data Organization

Understanding Computers: Today and Tomorrow, 15th Edition 11


6
How It Works Box

Column Databases
– Stores data by columns
instead of rows
– Improves performance
by minimizing the
time needed to read
the disk
– Used with data
warehouses and other
big data applications

Understanding Computers: Today and Tomorrow, 15th Edition 11


7
Quick Quiz

1. A column in a database in which customer names are stored would


be referred to as a .
a. field
b. record
c. table
2. True or False: Data validation procedures are used to ensure that
data entered into a database matches the specified type, format,
and allowable value.
3. The contains metadata about the database tables
in a database.

Answers:
1) a; 2) True; 3) data dictionary

Understanding Computers: Today and Tomorrow, 15th Edition 11


8
Database Classifications

• Single-User vs. Multiuser Database Systems


– Single-User Database System
• Located on a single computer
• Designed to be accessed by one user
• Widely used for personal applications and very small
businesses
– Multiuser Database System
• Designed to be accessed by multiple users (most
business databases today)

Understanding Computers: Today and Tomorrow, 15th Edition 11


9
Database Classifications

• Client-Server and N-Tier Database Systems


– Client-Server Database Systems
• Has both clients (front end) and at least one database
server (back end)

Understanding Computers: Today and Tomorrow, 15th Edition 12


0
Database Classifications

– N-Tier Database System


• Has more than two tiers
• Additional tiers typically
contain software referred to as
middleware
• Allows program code to be
separate from the database
• Code can be divided into any
number of logical components

Understanding Computers: Today and Tomorrow, 15th Edition 12


1
Database Classifications

• Centralized vs. Distributed Database Systems


– Centralized Database System
• Database is located on a single computer, such as a
server or mainframe
– Distributed Database System
• Data is physically divided among several computers
connected by a network, but the database logically
looks like it is a single database

Understanding Computers: Today and Tomorrow, 15th Edition 12


2
Database Classifications

Understanding Computers: Today and Tomorrow, 15th Edition 12


3
Database Classifications

• Disk-Based vs. In-Memory Database Systems


– Disk-Based Systems
• Data is stored on hard drives
– In-Memory Databases (IMDBs)
• Data is stored in main memory
• Dramatically faster than disk-based databases
• Good backup procedures are essential
• Used both in high-end systems where performance is
crucial and in small-footprint, embedded applications

Understanding Computers: Today and Tomorrow, 15th Edition 12


4
Quick Quiz

1. Which type of database system is beginning to be used in


high-end systems where performance is crucial?
a. In-memory databases
b. Disk-based databases
c. Single-user databases
2. True or False: With the n-tier database model, there is at least
one middle piece of software between the client and the
server.
3. With a(n) database system, the databases
used by the system are all located on a single computer.

Answers:
1) a; 2) True; 3) centralized
Understanding Computers: Today and Tomorrow, 15th Edition 12
5
Introduction to SQL
• What is SQL?
• SQL stands for Structured Query Language
• SQL lets you access and manipulate databases
• SQL became a standard of the American National
Standards Institute (ANSI) in 1986, and of the
International Organization for Standardization (ISO) in
1987
Introduction to SQL
• What Can SQL do?
• SQL can execute queries against a database
• SQL can retrieve data from a database
• SQL can insert records in a database
• SQL can update records in a database
• SQL can delete records from a database
• SQL can create new databases
• SQL can create new tables in a database
• SQL can create stored procedures in a database
• SQL can create views in a database
• SQL can set permissions on tables, procedures, and views
Introduction to SQL
• SQL is a Standard - BUT....
• Although SQL is an ANSI/ISO standard, there are
different versions of the SQL language.
• However, to be compliant with the ANSI standard, they
all support at least the major commands (such as
SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar
manner.
SQL Syntax
• Database Tables
• A database most often contains one or more tables.
Each table is identified by a name (e.g. "Customers" or
"Orders"). Tables contain records (rows) with data.
SQL SELECT Statement
• The SELECT statement is used to select data from
a database.
• The data returned is stored in a result table,
called the result-set.
• Here, column1, column2, ... are the field names of
the table you want to select data from.

• If you want to select all the fields available in the


table, use the following syntax:
SQL SELECT DISTINCT Statement
• The SELECT DISTINCT statement is used to return
only distinct (different) values.
• Inside a table, a column often contains many
duplicate values; and sometimes you only want to
list the different (distinct) values.
SQL 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.
SQL AND, OR and NOT Operators
• The WHERE clause can be combined with AND,
OR, and NOT operators.
• The AND and OR operators are used to filter
records based on more than one condition:
• The AND operator displays a record if all the conditions
separated by AND are TRUE.
• The OR operator displays a record if any of the
conditions separated by OR is TRUE.
• The NOT operator displays a record if the
condition(s) is NOT TRUE.
SQL AND, OR and NOT Operators
SQL ORDER BY Keyword
• The ORDER BY keyword is used to sort the result-
set in ascending or descending order.
• The ORDER BY keyword sorts the records in
ascending order by default. To sort the records in
descending order, use the DESC keyword.
SQL INSERT INTO Statement
• The INSERT INTO statement is used to insert new
records in a table.
• It is possible to write the INSERT INTO statement
in two ways.
• The first way specifies both the column names
and the values to be inserted:
SQL INSERT INTO Statement
• If you are adding values for all the columns of the
table, you do not need to specify the column
names in the SQL query. However, make sure the
order of the values is in the same order as the
columns in the table. The INSERT INTO syntax
would be as follows:
SQL UPDATE Statement
• The UPDATE statement is used to modify the
existing records in a table.
SQL DELETE Statement
• The DELETE statement is used to delete existing
records in a table.
SQL MIN() and MAX() Functions
• The MIN() function returns the smallest value of
the selected column.
• The MAX() function returns the largest value of
the selected column.
SQL COUNT(), AVG() and SUM()
Functions
• The COUNT() function returns the number of
rows that matches a specified criterion.
• The AVG() function returns the average value of a
numeric column.
• The SUM() function returns the total sum of a
numeric column.
SQL LIKE Operator
• The LIKE operator is used in a WHERE clause to
search for a specified pattern in a column.
• There are two wildcards often used in conjunction
with the LIKE operator:
• % - The percent sign represents zero, one, or multiple
characters
• _ - The underscore represents a single character
SQL LIKE Operator
SQL BETWEEN Operator
• The BETWEEN operator selects values within a
given range. The values can be numbers, text, or
dates.
• The BETWEEN operator is inclusive: begin and
end values are included.
SQL Joins
• A JOIN clause is used to combine rows from two
or more tables, based on a related column
between them.
• Let's look at a selection from the "Orders" table
and “Customers” table:
SQL Joins
• Then, we can create the following SQL statement
(that contains an INNER JOIN), that selects
records that have matching values in both tables:

You might also like