Module 3: Creating and Managing DatabasesOverviewCreating DatabasesDefining DatabasesPowerPoint PresentationRetrieving Database InformationCreating FilegroupsManaging DatabasesManaging Data and Log File GrowthMonitoring and Expanding a Transaction LogShrinking a Database or FileDropping a DatabaseIntroduction to Data StructuresHow Data Is StoredReviewModule 3: Creating and ManagingDatabasesOverviewCreating DatabasesCreating FilegroupsManaging DatabasesIntroduction to Data Structures Creating DatabasesDefining DatabasesHow the Transaction Log WorksSetting Database OptionsRetrieving Database InformationDefining DatabasesCREATE DATABASE SampleON PRIMARY ( NAME=SampleData, FILENAME='c:\Program Files\..\..\Data\Sample.mdf', SIZE=10MB, MAXSIZE=15MB, FILEGROWTH=20%) LOG ON ( NAME=SampleLog, FILENAME= 'c:\Program Files\..\..\Data\Sample.ldf', SIZE=3MB, MAXSIZE=5MB, FILEGROWTH=1MB)COLLATE SQL_Latin1_General_Cp1_CI_ASCREATE DATABASE SampleON PRIMARY ( NAME=SampleData, FILENAME='c:\Program Files\..\..\Data\Sample.mdf', SIZE=10MB, MAXSIZE=15MB, FILEGROWTH=20%) LOG ON ( NAME=SampleLog, FILENAME= 'c:\Program Files\..\..\Data\Sample.ldf', SIZE=3MB, MAXSIZE=5MB, FILEGROWTH=1MB)COLLATE SQL_Latin1_General_Cp1_CI_ASCreating a Database Defines: The name of the databaseThe size of the databaseThe files where the database will resideHow the Transaction Log Works Data modification is sent by applicationData modification is sent by application1111DiskModification is recorded in transaction log on diskModification is recorded in transaction log on disk3333Data pages are located in, or read into, buffer cache and modifiedData pages are located in, or read into, buffer cache and modified2222Buffer CacheDiskCheckpoint writes committed transactionsto databaseCheckpoint writes committed transactionsto database4444Retrieving Database InformationDetermine Database Properties by Using the DATABASEPROPERTYEX FunctionUse System Stored Procedures to Display Information About Databases and Database Parameterssp_helpdbsp_helpdb database_namesp_spaceused [objname]Creating FilegroupsNorthwind DatabaseDefault Filegroup OrderHistoryGroupsys...sys...sys...sys... sys...sys...sys...sys... sysuserssysuserssysuserssysusers sysobjectssysobjectssysobjectssysobjects ............ OrdersOrdersOrdersOrders CustomersCustomersCustomersCustomers ProductsProductsProductsProducts OrdHistYear2OrdHistYear2OrdHistYear2OrdHistYear2 OrdHistYear1OrdHistYear1OrdHistYear1OrdHistYear1 Northwind.mdfNorthwind.mdfC:\ D:\OrdHist1.ndfOrdHist1.ndfOrdHist2.ndfOrdHist2.ndfNorthwind.IdfNorthwind.IdfE:\ndf is data file;ldf is log file Managing DatabasesManaging Data and Log File GrowthMonitoring and Expanding a Transaction Log Shrinking a Database or FileDropping a DatabaseManaging Data and Log File GrowthALTER DATABASE Sample MODIFY FILE ( NAME = 'SampleLog', SIZE = 15MB)GOALTER DATABASE SampleADD FILE (NAME = SampleData2, FILENAME='c:\Program Files\..\..\ Data\Sample2.ndf', SIZE=15MB, MAXSIZE=20MB)GOALTER DATABASE Sample MODIFY FILE ( NAME = 'SampleLog', SIZE = 15MB)GOALTER DATABASE SampleADD FILE (NAME = SampleData2, FILENAME='c:\Program Files\..\..\ Data\Sample2.ndf', SIZE=15MB, MAXSIZE=20MB)GOUsing Automatic File GrowthExpanding Database FilesAdding Secondary Database FilesMonitoring and Expanding a Transaction LogMonitoring the Log Monitoring Situations That Produce Extensive Log ActivityMass loading of data into indexed tableLarge transactionsPerforming logged text or image operationsExpanding the Log When NecessaryShrinking a Database or FileShrinking an Entire DatabaseShrinking a Data File in the DatabaseShrinking a Database AutomaticallySet autoshrink database option to trueDBCC SHRINKDATABASE (Sample, 25)DBCC SHRINKDATABASE (Sample, 25)DBCC SHRINKFILE (Sample_Data, 10)DBCC SHRINKFILE (Sample_Data, 10)Dropping a DatabaseDROP DATABASE Northwind, pubsDROP DATABASE Northwind, pubsMethods of Dropping a DatabaseSQL Server Enterprise ManagerDROP DATABASE statementRestrictions on Dropping a DatabaseWhile it is being restoredWhen a user is connected to itWhen publishing as part of replicationIf it is a system database Introduction to Data StructuresHow Data Is StoredTypes of Pages and ExtentsPages That Manage File SpacePages That Track Tables and IndexesDatabaseDatabaseHow Data Is StoredExtent (8 contiguous 8-KB pages)Page (8 KB)Tables,IndexesDataMax row size = 8060 bytesData (file).mdf or .ndfLog (file).IdfReviewCreating DatabasesCreating FilegroupsManaging DatabasesIntroduction to Data
View Full Document