Session 7 Creating and Managing Databases. RDBMS and Data Management/ Session 7/2 of 27 Session Objectives Describe the system and user-defined databases.

Slides:



Advertisements
Similar presentations
9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
Advertisements

Module 4 Working with Databases. Module Overview Overview of SQL Server Databases Working with Files and Filegroups Moving Database Files.
Advantage Data Dictionary. agenda Creating and Managing Data Dictionaries –Tables, Indexes, Fields, and Triggers –Defining Referential Integrity –Defining.
©2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 5 Slide 1 IT390 Business Database Administration Unit 5 :
Tables Lesson 6. Skills Matrix Tables Tables store data. Tables are relational –They store data organized as row and columns. –Data can be retrieved.
SQL Server Data Protection and High Availability Anil Desai.
Module 3: Creating and Managing Databases. Overview Creating Databases Creating Filegroups Managing Databases Introduction to Data Structures.
Introduction to Structured Query Language (SQL)
Keith Burns Microsoft UK Mission Critical Database.
Module 7: Restoring Databases. Overview SQL Server Recovery Process Preparing to Restore a Database Restoring Backups Restoring Databases from Different.
Working with SQL and PL/SQL/ Session 1 / 1 of 27 SQL Server Architecture.
Backup Concepts. Introduction Backup and recovery procedures protect your database against data loss and reconstruct the data, should loss occur. The.
Database Configuration and Maintenance Database Configuration and Maintenance Exam / 30.
1 Chapter Overview Transferring and Transforming Data Introducing Microsoft Data Transformation Services (DTS) Transferring and Transforming Data with.
Chapter 2 Administrating DB Engine. Database Engine  The Database Engine is the core service for storing, processing, and securing data.  It provides.
Overview What is SQL Server? Creating databases Administration Security Backup.
Building Highly Available Systems with SQL Server™ 2005 Vineet Gupta Evangelist – Data and Integration Microsoft Corp.
Module 8: Server Management. Overview Server-level and instance-level resources such as memory and processes Database-level resources such as logical.
1 Chapter Overview Creating a User Database Setting Database Options Managing User Database Size Placing Database Files on Multiple Disks.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 13 Managing Databases with SQL Server 2000.
Chapter 4 SQL. SQL server Microsoft SQL Server is a client/server database management system. Microsoft SQL Server is a client/server database management.
Database Security and Auditing: Protecting Data Integrity and Accessibility Chapter 3 Administration of Users.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 2: Designing Physical Storage MCITP Administrator: Microsoft SQL Server 2005 Database Server Infrastructure Design Study Guide (70-443)
Learningcomputer.com SQL Server 2008 – Introduction to Transact SQL.
Module 3: Managing Database Files. Overview Introduction to Data Structures Creating Databases Managing Databases Placing Database Files and Logs Optimizing.
Database Technical Session By: Prof. Adarsh Patel.
Introduction to SQL Steve Perry
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
70-294: MCSE Guide to Microsoft Windows Server 2003 Active Directory, Enhanced Chapter 4: Active Directory Architecture.
I Copyright © Oracle Corporation, All rights reserved. Introduction.
Agenda for Today Chapter 5 –Skip Lesson 2 Review questions Midterm Chapter 6 Review questions.
Databases Lesson 5.
Chokchai Junchey Microsoft Product Specialist Certified Technical Training Center.
SQL/Lesson 4/Slide 1 of 45 Using Subqueries and Managing Databases Objectives In this lesson, you will learn to: *Use subqueries * Use subqueries with.
The protection of the DB against intentional or unintentional threats using computer-based or non- computer-based controls. Database Security – Part 2.
Module 11: Programming Across Multiple Servers. Overview Introducing Distributed Queries Setting Up a Linked Server Environment Working with Linked Servers.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
IT 456 Seminar 5 Dr Jeffrey A Robinson. Overview of Course Week 1 – Introduction Week 2 – Installation of SQL and management Tools Week 3 - Creating and.
Triggers A Quick Reference and Summary BIT 275. Triggers SQL code permits you to access only one table for an INSERT, UPDATE, or DELETE statement. The.
Module 1: Exploring Replication. Overview Understanding SQL Server Replication Setting Up Replication Understanding Agents in Replication Securing Replication.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Database structure and space Management. Database Structure An ORACLE database has both a physical and logical structure. By separating physical and logical.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents.
SQL Server 2005 Implementation and Maintenance Chapter 12: Achieving High Availability Through Replication.
14 Copyright © 2005, Oracle. All rights reserved. Backup and Recovery Concepts.
Connect with life Vinod Kumar Technology Evangelist - Microsoft
Learningcomputer.com SQL Server 2008 – Backup and Restore Database.
Session 1 Module 1: Introduction to Data Integrity
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Backup and Recovery - II - Checkpoint - Transaction log – active portion - Database Recovery.
14 Copyright © 2005, Oracle. All rights reserved. Backup and Recovery Concepts.
Praveen Srivatsa Director| AstrhaSoft Consulting blogs.asthrasoft.com/praveens |
SQL Server 2012 Session: 1 Session: 6 Creating and Managing Databases Data Management Using Microsoft SQL Server.
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
Log Shipping, Mirroring, Replication and Clustering Which should I use? That depends on a few questions we must ask the user. We will go over these questions.
SQL Basics Review Reviewing what we’ve learned so far…….
Microsoft SQL is known as RDMS (Relational Database Management System) which is developed by Microsoft and is highly used at corporate and enterprise.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
In this session, you will learn to: Manage databases Manage tables Objectives.
Agenda for Today  DATABASE Definition What is DBMS? Types Of Database Most Popular Primary Database  SQL Definition What is SQL Server? Versions Of SQL.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Understanding Core Database Concepts Lesson 1. Objectives.
SQL Database Management
Table spaces.
A Technical Overview of Microsoft® SQL Server™ 2005 High Availability Beta 2 Matthew Stephen IT Pro Evangelist (SQL Server)
Microsoft SQL Server 2014 for Oracle DBAs Module 3
Understanding Core Database Concepts
Presentation transcript:

Session 7 Creating and Managing Databases

RDBMS and Data Management/ Session 7/2 of 27 Session Objectives Describe the system and user-defined databases in SQL Server Outline the key features of the AdventureWorks sample database. Describe how to add filegroups and transaction logs. List types of database modifications and describe how to drop a database. Describe database snapshots.

RDBMS and Data Management/ Session 7/3 of 27 SQL Server Supported Databases SQL Server 2005 supports the following databases: System Database User-defined databases Sample Databases Created by SQL Server to store information about SQL Server Also manages user-defined databases. SQL Server 2005 users create user-defined databases. Stores user data. SQL Server provides sample databases for the users to work with SQL Server A new sample database, AdventureWorks, has been introduced in SQL Server 2005.

RDBMS and Data Management/ Session 7/4 of 27 System Databases SQL Server 2005 provides and supports these system databases: DatabaseDescription masterThe database records all system-level information of an instance of SQL Server. msdbThe database is used by SQL Server Agent for scheduling database alerts and various jobs modelThe database is used as the template for all databases to be created on the particular instance of SQL Server resourceThe database is a read-only database. It contains system objects included with SQL Server tempdbThe database holds temporary objects or intermediate result sets.

RDBMS and Data Management/ Session 7/5 of 27 Modifying System Data Users are not allowed to directly manipulate the information in system tables, system stored procedures, and catalog views. Users can administer the system and manage all users and database objects through: SQL Server Management Studio SQL Server Management Objects (SMO) application programming interface Transact-SQL scripts and stored procedures modify System data

RDBMS and Data Management/ Session 7/6 of 27 Viewing System Data Database applications view catalog and system information by using any of the following: System catalog views SQL Server management objects Catalog functions, methods, attributes, or properties of the data API Stored Procedures and Functions Ettreeryreyr Ertetertetet tettwet Viewing System data

RDBMS and Data Management/ Session 7/7 of 27 User-defined Databases The information needed to create a user-defined database: Name of the database Owner of the database Size of the database Files and Filegroups used to store it CREATE DATABASE database_name [ ON [ PRIMARY ] [ [,...n ] [, [,...n ] ] [ LOG ON { [,...n ] } ] ] [ COLLATE collation_name ] ] [;] Syntax for creating a database:

RDBMS and Data Management/ Session 7/8 of 27 User-defined Databases User database size can be expanded, shrunk or be dropped as per the need of the user. ALTER DATABASE database_name { | | MODIFY NAME = new_database_name | COLLATE collation_name }[;] The ownership of a user database can be changed using spchangedbowner stored procedure. sp_changedbowner = ] ‘login’ Syntax for modifying a database: Syntax for changing the owner using sp_changedbowner:

RDBMS and Data Management/ Session 7/9 of 27 User-defined Databases For each database, the database options are unique. The database options can be set using the SET clause of the ALTER DATABASE statement. Following table shows details of options for SQL Server 2005: Option TypeDescription Automatic optionsControls automatic behavior of database. Cursor optionsControls cursor behavior. Recovery optionsControls recovery models of database. State optionsControls American National Standards Institute (ANSI) compliance.

RDBMS and Data Management/ Session 7/10 of 27 User-defined Databases Example for creating database: CREATE DATABASE [Customer_DB] ON PRIMARY ( NAME = N’Customer_DB’, FILENAME = N’ C:\Program Files\Microsoft SQL Server\MSSQL.1\ MSSQL\Data\Customer_DB.mdf’) LOG ON ( NAME = N’Customer_DB_log’, FILENAME = N’ C:\Program Files\Microsoft SQL Server\MSSQL.1 \MSSQL\Data\Customer_DB_log.ldf’) COLLATE SQL_Latin1_General_CP1_CI_AS Example for modifying database: ALTER DATABASE Customer_DB MODIFY NAME = CUST_DB

RDBMS and Data Management/ Session 7/11 of 27 User-defined Databases Example for changing database owner: USE CUST_DB EXEC sp_changedbowner ‘sa’ USE CUST_DB; ALTER DATABASE CUST_DB SET AUTO_SHRINK ON Example for setting database options:

RDBMS and Data Management/ Session 7/12 of 27 AdventureWorks Databases AdventureWorks is the new addition to SQL Server 2005 sample databases. Adventure Works Cycles is a fictitious large, multinational cycle manufacturing company introduced as a scenario in the database. The sample database consists of the following parts: AdventureWorks: Sample Online Transaction Processing (OLTP) database AdventureWorksDW: Sample Data warehouse AdventureWorksAS: Sample Analysis Services database

RDBMS and Data Management/ Session 7/13 of 27 Filegroups and Transaction Logs 1-7 FILES: Actual physical storage units Contain database objects Files have a logical and a physical name Filegroups: Collections of files that are grouped for better performance and easier management. A single logical filegroup can contain multiple physical files. Each filegroup is used to group related files that together store a database object. Database objects like tables and indexes can be created on specific filegroups. Filegroups can be taken as back ups and restored separately. The following table shows the details of filegroups supported by SQL Server 2005:

RDBMS and Data Management/ Session 7/14 of 27 Filegroups and Transaction Logs 2-7 FilegroupDescription PrimaryThe filegroup that consists of the primary file. All system tables are placed inside the primary filegroup. User-definedAny filegroup that is created by the user at the time of creating or modifying databases. Adding Filegroups to database: Filegroups can be added for a new database at the time of database creation or for an existing database. A file cannot be a member of more than one filegroup. Files cannot be moved to a different filegroup after files have been added to the database. Filegroups can contain only data files and no transaction log files.

RDBMS and Data Management/ Session 7/15 of 27 Filegroups and Transaction Logs 3-7 Adding Filegroups during creation of database Syntax for filegroup addition while creating a database: CREATE DATABASE database_name [ ON [ PRIMARY ] [ [,...n ] [, [,...n ] ] [ LOG ON { [,...n ] } ] ] [ COLLATE collation_name ] ] [;]

RDBMS and Data Management/ Session 7/16 of 27 Filegroups and Transaction Logs 4-7 Adding Filegroups to an existing database Syntax for filegroup addition to an existing database: ALTER DATABASE database_name { | | MODIFY NAME = new_database_name | COLLATE collation_name } [;]

RDBMS and Data Management/ Session 7/17 of 27 Filegroups and Transaction Logs 5-7 Viewing Filegroup Information Database, file, partition, and filegroup properties can be viewed using a variety of catalog views, system functions, and stored procedures. Details of these functions are summarized in the table: FunctionsDescription DB_IDThis function returns the database identification number. DB_NAMEThis function returns the database name. FILE_IDThis functions returns the file identification number for a logical file name in the current database FILE_NAMEThis function returns the logical name for the given file identification number.

RDBMS and Data Management/ Session 7/18 of 27 Filegroups and Transaction Logs 6-7 Transaction Transaction is a set of operations that must happen together. Actions are first recorded to transaction log. When that is complete, operations applied to database. Rollback and data recovery Recovery of individual transactions Recovery of all incomplete transactions when SQL Server is started Rolling a restored database, file, filegroup, or page forward to the point of failure Supporting transactional replication Standby server solutions Transaction Log supports

RDBMS and Data Management/ Session 7/19 of 27 Filegroups and Transaction Logs 7-7 Adding Log files to a database Syntax for log file addition to a database: ALTER DATABASE database_name {... } [;] ::= { ADD FILE [,...n ] [ TO FILEGROUP { filegroup_name | DEFAULT } ] | ADD LOG FILE [,...n ] | REMOVE FILE logical_file_name | MODIFY FILE }

RDBMS and Data Management/ Session 7/20 of 27 Database Modification Methods 1-2 Type of modifications Modification methods Increasing the size of a database ALTER DATABASE statement or the database properties in SQL Server Management Studio. Changing the physical location of a database ALTER DATABASE statement. Adding data or transaction log files ALTER DATABASE statement or the database properties in SQL Server Management Studio. Shrinking a databaseDBCC SHRINKDATABASE statement or the Shrink Database option in SQL Server Management Studio, accessed through the node for the specific database. Shrinking a database file DBCC SHRINKFILE statement. Deleting data or log files ALTER DATABASE statement or the database properties in SQL Server Management Studio. Adding a filegroup to a database ALTER DATABASE statement or the database properties in SQL Server Management Studio.

RDBMS and Data Management/ Session 7/21 of 27 Database Modification Methods 2-2 Type of modifications Modification methods Changing the default filegroup ALTER DATABASE statement. Changing database options ALTER DATABASE statement or the database properties in SQL Server Management Studio. Changing database owner sp_changedbowner system stored procedure. Dropping a database The files and the data associated with the database is automatically deleted from the disk when the database is deleted. Syntax: DROP DATABASE { database_name }

RDBMS and Data Management/ Session 7/22 of 27 Database Snapshots Creating a database snapshot: Database snapshot is a new feature in Microsoft SQL Server 2005 which provides a read-only, static view of a SQL Server database. If user makes a mistake in the source database, the source database can be reverted to the previous state when the snapshot was created. Syntax: CREATE DATABASE database_snapshot_name ON ( NAME = logical_file_name, FILENAME = ‘os_file_name’ ) [,...n ] AS SNAPSHOT OF source_database_name [;]

RDBMS and Data Management/ Session 7/23 of 27 Database Snapshots Database created Snapshot created Data gets modifiedSnapshot is restored

RDBMS and Data Management/ Session 7/24 of 27 Database Snapshots AdvantagesDisadvantages Provide a convenient, read-only copy of data. When queried, no deterioration of performance. Snapshot files are small and are very quick to create. Snapshot backup cannot be created. Snapshot must exist on the same database server as that of the source database. A new user cannot be granted access to the data in a snapshot.

RDBMS and Data Management/ Session 7/25 of 27 Summary SQL Server supports system as well as user-defined databases. System databases are used to store information about SQL Server 2005, and manage user databases. User-defined databases are used to store user information. User-defined databases can be created using the CREATE DATABASE statement. SQL Server 2005 filegroups contain data files. A transaction log present in SQL Server 2005 records all transactions and modifications in the database, made by each transaction. A database snapshot is a read-only, static view of a source database.