Compendium Database
Compendium Database
Compendium Database
1. SQL Server – Overview M MS SQL Server by Thobius Joseph, 0717341960, UOI, 2020
Lecture One
Content:
0. Who is Database administrator (DBA)?
DBA is a specialized computer systems administrator who:
Unsure data integrity, by ensuring that data are secure from unauthorized access but is
available to users. How? By settings logins, users, permissions and other techniques
like firewall and Access List (ACL)
Maintains a successful database environment by directing or performing all related
activities to keep the data secure. How? By configuring database program, services,
protocols, policy …
Has knowledge and experience with a wide range of database management products
such as Oracle-based software, SAP and SQL.
Performing risk management related to database. How? Database backup &
restoration, Power outages cases. How? By using management tools.
Use, designing, implementing and maintaining the database system.
Establishing policies and procedure related to the organization‟s data management
policy
Perform database installation and upgrade
1. What is server?
Refer to the types of computers
Microcomputers e.g.: Laptops, tablets, mobile phones, desktop. notebook
Minicomputers e.g. : Workstations
Mainframe e.g. : Computers in data centres
Super frame e.g. : International connecting computers
A Server term sometimes is used to refer the computer which performing server
functionalities. Henceforth, it‟s important to determine which type of a computer you
are going to implement server functionalities, because these server functionalities
always demand some kind of computer specifications: The main specifications that
most of server functionality will demands are
CPU
RAM
Storage capacity
Example: To run server functionality for Microsoft SQL server 2012 express edition
you will need a computer with at least 1 CPU, 1GB memory and 10 GB storage (for
your database). Hence from above types of computer you will determine which one is
suitable for your environment and demands.
The term Server may also refer to :
- A server OS or
- A server program (application software) that is dedicated
to managing resources for server functionality. Servers are often referred to as
dedicated because they carry out hardly any other tasks apart from their server tasks.
Most of time when we speak about server we are meaning combination of both
computer, OS and a program which in the end they provides server functionalities.
Examples are
Web server
Database server
Media server
Proxy server
Server operating system (OS) is a type of operating system that is designed to be
installed and used on a server computer. From the types of operating systems. The
server OS falls on Network Operating System (NOS) type because their main function
is sharing of their resources such as database & webpages in a network. Some
common examples of server OSs include:
Red Hat Enterprise Linux
Windows Server: Example Microsoft windows server 2003, 2008, 2012.
Mac OS X Server
Server Programs are type of application software designed to provide server
functionalities. While most of server needs a dedicated computer plus its server OS,
these program can run in any computer with any OS.
By installing these program to your computer which running any OS your turning
your computer into a server.
Most of available server programs are developed to implement functionalities of
database servers, therefore are called Database Management Systems (DBMS).
Example: FTP server program, MySQL, PostgreSQL, Microsoft Access, SQL server,
FileMaker, Oracle and FoxPro.
2. Software layers
You can divide your developed software in layers or partitions, whereby each
partition is developed to accomplish specific groups of task, and this is basic method
of developing server programs (DBMS). The followings are three layer (partition )
you can use divide your software:
Presentation Layer ( client layer)
Application Layer (Business logic layer)
Data Layer
• Presentation Layer: It is also known as Client layer. Top most layer of an
application. This is the layer we see when we use software. By using this layer we can
access the webpages. The main functionality of this layer is to communicate with
Application layer. This layer passes the information which is given by the user in
terms of keyboard actions, mouse clicks to the Application Layer.
For example, login page of Gmail where an end user could see text boxes and buttons
to enter user id, password and to click on sign-in.
In a simple word, it is to view the application, like a GUI
• Application Layer: It is also known as Business Logic Layer which is also known as
logical layer. As per the Gmail login page example, once user clicks on the login
button, Application layer interacts with Database layer and sends required information
to the Presentation layer. It controls an application‟s functionality by performing
detailed processing. This layer acts as a mediator between the Presentation and the
Database layer. Complete business logic will be written in this layer.
In a simple words, it is to perform operations on the application, consist of IF else
statements, data conversions.
• Data Layer: The data is stored in this layer. Application layer communicates with
Database layer to retrieve the data. It contains methods that connects the database and
performs required action e.g.: insert, update, delete etc.
• In simple words, it is to share and retrieve the data.
SQL Server 2012 installation, SQL server Management Studio installation and
logins (demo in class)
Lecture Two
Data
Data is unprocessed information. Some scholars go to fields to obtain a lot of data for
their topic of study. When these data are processed they will deliver some kind of
information. For example the table below represent list of student with smart phones.
1. When data in table are accessed electronically we will know that 3 students have
smart phones and 3 do not have, which is the information our data from the table
provide us. We can‟t use names to determine gender
2. From table we are missing some
Information such as how many
Women do have smart phones and
How many men do have smart phone.
This is due our data are not
Well organized.
3. The solution here is to reformulate our table so that at least it can provide us with
much information we can obtain.
Database
A database is an organized collection of data, stored and accessed electronically.
Formally, a "database" refers to a set of related data and the way it is organized.
Database designers typically organize the data in such that are easy to provide
necessary information. A Database is a collection of related data organized in a way
that data can be easily accessed, managed and updated. Database can be software
based or hardware based, with one sole purpose, storing data.
Therefore from our previous table, the new table would look like shown below:
From this table we need to increase one information; number of women and men with
smart phones.
In order to access this data you need computer software. This software‟s developed
for the purposes of database access are called "database management system"
(DBMS). DBMS allows users to interact with one or more databases and provides
access to all of the data contained in the database (although restrictions may exist that
limit access to particular data).
A database is generally stored in a DBMS-specific format which is not portable, but
different DBMSs can share data by using standards such as SQL and ODBC or JDBC.
Therefore Sometimes a DBMS is loosely referred to as a "database"
Why Database Management System (DBMS)?
During early computer days, data was collected and stored on tapes, which were
mostly write-only, which means once data is stored on it, it can never be read again.
They were slow and bulky, and soon computer scientists realized that they needed a
better solution to this problem.
Larry Ellison, the co-founder of Oracle was amongst the first few, who realized the
need for a software based Database Management System.
What is DBMS?
A DBMS is software that allows creation, definition and manipulation of database,
allowing users to store, process and analyze data easily. DBMS provides us with an
interface or a tool, to perform various operations like creating database, storing data in
it, updating data, creating tables in the database and a lot more.
DBMS also provides protection and security to the databases. It also maintains data
consistency in case of multiple users.
Here are some examples of popular DBMS used these days:
MySql, Oracle, SQL Server, IBM DB2, PostgreSQL and Amazon SimpleDB (cloud
based) etc.
A database management system has following characteristics:
Data stored into Tables: Data is never directly stored into the database. Data is stored into
tables, created inside the database. DBMS also allows having relationships between tables
which makes the data more meaningful and connected. You can easily understand what type
of data is stored where by looking at all the tables created in a database.
Reduced Redundancy: In the modern world hard drives are very cheap, but earlier when
hard drives were too expensive, unnecessary repetition of data in database was a big problem.
But DBMS follows Normalization which divides the data in such a way that repetition is
minimum.
Data Consistency: On Live data, i.e. data that is being continuously updated and added,
maintaining the consistency of data can become a challenge. But DBMS handles it all by
itself.
Support multiple user and Concurrent Access: DBMS allows multiple users to work on it
(update, insert, and delete data) at the same time and still manages to maintain the data
consistency.
Query Language: DBMS provides users with a simple Query language, using which data
can be easily fetched, inserted, deleted and updated in a database.
Security: The DBMS also takes care of the security of data, protecting the data from un-
authorized access. In a typical DBMS, we can create user accounts with different access
permissions, using which we can easily secure our data by restricting user access.
DBMS supports transactions, which allows us to better handle and manage data integrity in
real world applications where multi-threading is extensively used.
Advantages of DBMS
Segregation of application program.
Minimal data duplicity or data redundancy.
Easy retrieval of data using the Query Language.
Reduced development time and maintenances need.
With Cloud Datacenters, we now have Database Management Systems capable of
storing almost infinite data.
Seamless integration into the application programming languages which makes it very
easier to add a database to almost any application or website.
Disadvantages of DBMS
It's Complexity.
Except MySQL, which is open source, licensed DBMSs are generally costly.
They are large in size.
The database management system can be divided into five major components, they
are :
Hardware
Software
Data
Procedures
Database Access Language
Database model
A database model is one that determines the logical structure of data in a database. It
also determines in which manner data can be stored, organized, and manipulated. The
most popular example of a database model is the relational model, which put data
inform of table. A table consist of columns and rows.
Below figure shows some types of database models
Hierarchical Model
This database model organizes data into a tree-like-structure, with a single root, to which all
the other data is linked. The hierarchy starts from the Root data, and expands like a tree,
adding child nodes to the parent nodes.
In this model, a child node will only have a single parent node.
This model efficiently describes many real-world relationships like index of a book, recipes
etc.
In hierarchical model, data is organized into tree-like structure with one one-to-many
relationship between two different types of data, for example, one department can have many
courses, many professors and of-course many students.
Network Model
This is an extension of the Hierarchical model. In this model data is organized more like a
graph, and are allowed to have more than one parent node. In this database model data is
more related as more relationships are established in this database model. Also, as the data is
more related, hence accessing the data is also easier and fast. This database model was used
to map many-to-many data relationships. This was the most widely used database model,
before Relational Model was introduced.
Entity-relationship Model
In this database model, relationships are created by dividing object of interest into
entity and its characteristics into attributes.
Different entities are related using relationships.
E-R Models are defined to represent the relationships into pictorial form to make it
easier for different stakeholders to understand.
This model is good to design a database, which can then be turned into tables in
relational model (see figure below).
Let's take an example, If we have to design a School Database, then Student will be an
entity with attributes name, age, address etc. As Address is generally complex, it can
be another entity with attributes street name, pin code, city etc., and there will be a
relationship between them
Relational Model
In this model, data is organized in two-dimensional tables and the relationship is maintained
by storing a common field. This model was introduced by E.F Codd in 1970, and since then it
has been the most widely used database model, in fact, we can say the only database model
used around the world. The basic structure of data in the relational model is tables. All the
information related to a particular type is stored in rows of that table.
Hence, tables are also known as relations in relational model.
Database Objects
A database object is any defined object in a database that is used to store or reference
data. Anything which we make from create command is known as Database Object.
A database (relational database) consisting of the following objects:
Tables
Queries
Views
Stored Procedures
Functions
Sequence – Generates primary key values
Index – Improves the performance of some queries
If you do not have an index on the column, then a full table scan occurs.
Synonym – Alternative name for an object
Trigger
Tables
Tables are the main building blocks of any database. This is where all the information
will be stored. A table consists of rows (records) and columns (fields). A row or
record contains all the information pertaining to one topic. A column or field is once
piece of information. Above is a small example of records and fields.
When you have many tables in your database and you need to connect them, you will
use technique called relationship. Consider figure below:
All of these tables are connected by a term called relationships. If you look closely in
Figure, you will see that inside each table there is a reference to another table's field,
this means that in some table there‟s one or more columns which can be found in
another or others tables. This is what forms a relationship between tables.
A relationship becomes possible when there is a
Primary key(PK) inside one table referencing
a Foreign key(FK).
Basically primary key (in 1st table) and
foreign key (in 2nd table) will be the field with
same name. In 2nd table were we mark one of our
column as Foreign key, we should mark also another
column as Primary key. Consider table
Students and Courses as 1st Table and
StudentInfo as 2nd table; StudentNo column in
1st table is Primary key and in 2nd is foreign key,
also in 2nd we have CourseID as primary key.
Queries
Now that we know where and how to store data, we need to know how to access that
data. This is done through a database query. You usually have to write a query to
extract the needed information from the appropriate tables.
In a well-designed database, the data that you want to present through a windows
form or report is usually located in multiple tables. A query can pull the information
from various tables and assemble it for display in the form or report.
A query can either be a request for data results from your database or for action on the
data, or for both. A query can give you an answer to a simple question, perform
calculations, combine data from different tables, add, change, or delete data from a
database.
Queries are developed using specific language such as SQL and T-SQL. Example of
query SELECT, DELETE, and UPDATE query.
Views
Is virtual table. This table is generated by query. This virtual table can contain some
column from one table (a subset of a table) or mixed column from multiple tables
(Views can join and simplify multiple tables into a single virtual table).
Stored Procedures
A Stored Procedure is a sequence of SQL code that can perform tedious tasks quickly.
By making use of Stored Procedures, you will save a lot of time and won't need to run
each query (that can reside in a Stored Procedure) manually.
These procedures are stored in the database data dictionary. To save time and memory,
extensive or complex processing that requires execution of several queries statements
you can save them into stored procedures, and all applications call the procedures.
Stored procedures may also contain declared variables for processing data and cursors
that allow it to loop through multiple rows in a table. Stored-procedure flow-control
statements typically include IF, WHILE, LOOP, REPEAT, and CASE statements, and
more. Stored procedures can receive variables, return results or modify variables and
return them, depending on how and where the variable is declared.
Functions
There are many functions inside the in any query language. These functions can help
with string manipulation, date manipulation as well as computing Averages, just to
name a few.
Databases in MS SQL Server, two types of databases are available.
System databases
User Databases
System Databases System databases are created automatically when we install MS
SQL Server. Following is a list of system databases:
Master
Model
MSDB
Tempdb
Resource (Introduced in 2005 version)
Distribution (It‟s for Replication feature only)
Contents
1. What is SQL Server?
2. SQL Server 2012 installation (Demo) and confirm for successfully installations
- Protocols for SQL SERVER instance; Shared Memory, Named Pipe and TCP/IP
Required Knowledge
This course is aimed at fostering the development of the concept and the skills of the students
that are required to perform the duties of Database Administrator (DBA) in organizations
using large relational databases. Students develop coherent plans for security, disaster
recovery, backup and restore, replication and other administrative tasks. Major topics will
include database security, authentication, granting permission, multiuser issues and
replication.
• The Database Engine consists of a relational engine that processes queries and a
storage engine that manages database files, pages, pages, index, etc. The
database objects such as stored procedures, views, and triggers are also created
and executed by the Database Engine.
Relational Engine
The Relational Engine contains the components that determine the best way to
execute a query. The relational engine is also known as the query processor.
The relational engine requests data from the storage engine based on the input query
and processed the results.
Some tasks of the relational engine include querying processing, memory
management, thread and task management, buffer management, and distributed query
processing.
Storage Engine
The storage engine is in charge of storage and retrieval of data from the storage
systems such as disks and SAN.
SQLOS
Under the relational engine and storage engine is the SQL Server Operating System or
SQLOS.SQLOS provides many operating system services such as memory and I/O
management. Other services include exception handling and synchronization services.
SQL Server Tools
The common tools are:
SQL server management studio (SSMS)
It access, configure, manage, administer, and develop all components of SQL
Server.
for GUI operation instead of command line method, hence you connecting to
server by using SSMS
SQL server configuration manager
Use SQL Server Configuration Manager to configure SQL Server services and
configure network connectivity. Configuration Manager runs on Windows. It
can configure:
A. For SQL Server Services- control services (start or stopping …)
- SQL Server Network Configuration
- Protocols for SQL SERVER instance; Shared Memory, Named Pipe and TCP/IP
B. For SQL Native Client Configuration
- Client Protocols; Shared Memory, Named Pipe and TCP/IP