1
5/15/17
Chapter 1
Creating Databases and Database Files
5/15/17
Agenda
•
•
•
•
Introduction to database
Creating database
Managing database
Maintainance to database
2
3
5/15/17
Database
•
•
Database:
•
A collection of data that are related in a meaningful way, which can be accessed in di fferent logical orders
Database Management System (DBMS):
•
A general purpose software package designed to store and manage database
5/15/17
Simplified database system environment
4
5/15/17
5
Database example
•
A UNIVERSITY database for maintaining information concerning students, courses, and grades in a
university environment
•
We have:
STUDENT file stores data on each student
COURSE file stores data on each course
SECTION file stores data on each section of each course
GRADE_REPORT file stores the grades that students receive
PREREQUISITE file stores the prerequisites
5/15/17
Database example
6
5/15/17
Database example
7
8
5/15/17
DBMS
•
Objectives of DBMS:
•
Data availability: users can easily access the data.
•
Data integrity: the data available in the database is a reliable data
•
Data security: only authorized users can access the data.
•
Data Independence: the user to store,update, and retrieve data in an e fficient manner.
9
5/15/17
Three-Schema Architecture
• Defines DBMS schemas at three levels:
•
Internal schema at the internal level to describe physical storage structures and access paths
(e.g indexes).
•
Conceptual schema at the conceptual level to describe the structure and constraints for the
whole database for a community of users.
•
External schemas at the external level to describe the various user views.
5/15/17
Three-Schema Architecture
10
5/15/17
11
Introduction to SQL Server 2008
•
MS SQL Server is a Relational Database Management System (RDBMS) designed for use in a
network environment.
•
RDBMS is system for storing, manipulating data in a series of related table.
12
5/15/17
Introduction to SQL Server 2008
• MS SQL Server supports 2 computing models:
•
Client/server application model:
13
5/15/17
Introduction to SQL Server 2008
• MS SQL Server supports 2 computing models:
•
Distributed computing model:
14
5/15/17
Introduction to SQL Server 2008
• SQL 2008 editions
Core Editions
Enterprise
Standard
Specialized Editions
Workgroup
Web
Free Editions
Developer
Express
Compact 3.5
Enterprise
Shared data
Remote offices that
For web
Full featured
Entry level
Embedded
workloads that
scenarios in
need local instances
application
edition for
database, ideal for
database for
need redundancy
departments and
of company data
hosting
development and
learning and ISV
developing
and built-in
small to large
testing only
redistribution
desktop and
Business
businesses
Intelligence
mobile application
5/15/17
Overview of database component
• Data files
•
Transaction log
•
Filegroup
•
Data Pages
•
Extend
15
5/15/17
Overview of database component
16
17
5/15/17
Overview of database component
• Data files
• Primary – system objects:
• database.mdf
• Stored in SQL Server’s data directory “C:\Program Files\Microsoft
SQLServer\MSSQL.1\MSSQL\DATA”
• Secondary – user objects
• .ndf
• Optional way to spread your database content over multiple files.
18
5/15/17
Overview of database component
• Transaction log
•
Records data action
•
Used for recovery
•
Use the .ldf file extension
19
5/15/17
Overview of database component
• Filegroup
•
a logical grouping of data files that hold all data and database objects defined for the database.
•
Primary filegroup:
•
•
Made up of the primary data file and any additional user-defined data files.
Store all system references for the database including pointers to objects defined in the resource database.
20
5/15/17
Overview of database component
• Filegroup
•
Secondary filegroup:
•
Control over what data is stored in what location.
•
Without user-defined filegroups, all data is stored in the Primary filegroup, so the flexibility and scalability of the
database are reduced dramatically.
21
5/15/17
Overview of database component
•
All the data from tables and indexes and the metadata that describes that data is organized in
storage objects
•
Extents
•
Data pages.
22
5/15/17
Overview of database component
• Extent:
• Basic unit of data scope
• file storage structure that is 64 KB in size.
• There are two types of extents: mixed extents and uniform extents.
• Mixed extents: contain pages from more than one object.
• Uniform extents: contain eight contiguous pages that belong to the
same objec
23
5/15/17
Overview of database component
• Data page:
•
Basic unit of storage management
•
contain data rows from tables
24
5/15/17
Overview of database component
• Schema:
•
container for database objects
•
assign permissions to the objects it contains.
•
Ex: you may create a schema called HumanResource and place all your employee tables and stored
procedures into it
•
Within the schema, objects cannot have duplicate names. However, objects can have the same name if
they exist in different schemas.
25
5/15/17
Overview of database component
• Schema:
•
A database principal is assigned ownership of a schema.
•
Ex: FredF is created in the AdventureWorks2008 DB and assigned the default schema of Sales. CreditCard table
belongs to Sales schema
•
If FredF logs in and executes the query:
1. SELECT * FROM CreditCard
The content of CreditCard will be returned
2. SELECT * FROM Person
what will be return if Person table doesn’t exist in Sales schema??