This example illustrates creating a Microsoft® SQL Server™ database by using SQL-DMO objects.
When using SQL Server Enterprise Manager for database creation, database data files are created so that file growth occurs in fixed size chunks. By default, a database file created using SQL-DMO exhibits percentage growth behavior. The sample reflects the default database data file growth settings for SQL Server Enterprise Manager.
The sample does not specify an initial size for either database data or log data files. The default value determined by SQL Server is used.
Dim oDatabase As New SQLDMO.Database
Dim oDBFileData As New SQLDMO.DBFile
Dim oLogFile As New SQLDMO.LogFile
oDatabase.Name = "Northwind"
' Define the PRIMARY data file.
oDBFileData.Name = "NorthData1"
oDBFileData.PhysicalName = "c:\mssql7\data\northwnd.mdf"
oDBFileData.PrimaryFile = True
' Specify file growth in chunks of fixed size for all data files.
oDBFileData.FileGrowthType = SQLDMOGrowth_MB
oDBFileData.FileGrowth = 1
oDatabase.FileGroups("PRIMARY").DBFiles.Add oDBFileData
' Define the database transaction log.
oLogFile.Name = "NorthLog1"
oLogFile.PhysicalName = "c:\mssql7\data\northwnd.ldf"
oDatabase.TransactionLog.LogFiles.Add oLogFile
' Create the database as defined. Note: Create and connect of SQLServer
' object used is not illustrated in this example.
oSQLServer.Databases.Add oDatabase
Database Object | FileGroup Object |
DBFile Object | LogFile Object |