Bài giảng Cơ sở dữ liệu nâng cao Chapter 1 Creating databases and database files. Nội dung chính trong chương này gồm có Introduction to database, creating database, managing database, maintainance to database. Mời các bạn cùng tham khảo.
1 5/15/17 Chapter Creating Databases and Database Files 5/15/17 Agenda • • • • Introduction to database Creating database Managing database Maintainance to database 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 5/15/17 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 5/15/17 Database example 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 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 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: SELECT * FROM CreditCard The content of CreditCard will be returned SELECT * FROM Person what will be return if Person table doesn’t exist in Sales schema?? 5/15/17 SQL Server 2008 Database • System database: • Five system databases: master, model, msdb,and tempdb • Created to store system information and support database operations • Resource database is invisible • The other database are visible during normal database operations • User database: • databases that are created by any server login 26 27 5/15/17 SQL Server 2008 Database • Database Planning: • determine how much disk space will be required to support the database • Database Planning steps: • Take the database prototype (the test or development version) and fill it with an appropriate amount of test data • Check the size of the data file on disk, and then multiply it by 1.5 • The resulting file size should be sufficient to accommodate the initial data load of the new database with some room to spare 28 5/15/17 SQL Server 2008 Database • Planning the size of the transaction log file: • How big the average transaction is that will be executed • How often the transactions will take place • What is the physical structure of the tables being modified 29 5/15/17 Creating a database • CREATE DATABASE Research on PRIMARY (NAME = ResearchPrimary, FILENAME =' D:\SQL\FG\ResearchPrimary.mdf', SIZE = 500MB, MAXSIZE = 700, FILEGROWTH=20); • ALTER DATABASE Research on FILEGROUP RESEARCH1 (NAME = ResearchPrimary, FILENAME =' D:\SQL\FG\Research1.ndf‘, SIZE = 500MB, MAXSIZE = 700, FILEGROWTH=20); 5/15/17 Database snapshot • A point-in-time, static, Read Only view of a database • Reflect the point in time when the database is copied 30 5/15/17 31 Database snapshot • Can not be backed up Since the snapshot is a combination of data retrieved from the source database and data stored internally, it is impossible to actually back up the snapshot • Database Snapshots cannot be modified • Source databases cannot be dropped while a snapshot exists • Source databases cannot be restored to a point in time prior to the creation of the snapshot while the snapshot exists 32 5/15/17 Database snapshot • The syntax for the creation of a snapshot : CREATE DATABASE database_snapshot_name ON (NAME = logical_file_name, FILENAME = 'os_file_name') [ , n ] AS SNAPSHOT OF source_database_name Ex:CREATE DATABASE AdventurWorks_snapshot ON (NAME = 'AdventureWorks_Data' , FILENAME = 'C:\temp\snapshot_DB.mdf') AS SNAPSHOT OF AdventureWorks; ...5 /15 /17 Agenda • • • • Introduction to database Creating database Managing database Maintainance to database 5 /15 /17 Database • • Database: • A collection of data... logical orders Database Management System (DBMS): • A general purpose software package designed to store and manage database 5 /15 /17 Simplified database system environment 5 /15 /17 Database example... prerequisites 5 /15 /17 Database example 5 /15 /17 Database example 5 /15 /17 DBMS • Objectives of DBMS: • Data availability: users can easily access the data • Data integrity: the data available in the database