Creating user defined filegroups for .ndf files

  • I'm trying to create a Database with data1.mdf in the primary and data2.ndf, data3.ndf in userdefined filegroup in vb.net. the SQL Statements are as follows:

    CREATE DATABASE MyDB

    ON PRIMARY

      ( NAME='MyDB_Primary',

       FILENAME=

          'c:\Program Files\Microsoft SQL Server\MSSQL\data\data1.mdf',

       SIZE=4,

       MAXSIZE=10,

       FILEGROWTH=1),

    FILEGROUP MyDB_FG1

      ( NAME = 'MyDB_FG1_Dat1',

       FILENAME =

          'c:\Program Files\Microsoft SQL Server\MSSQL\data\data2.ndf',

       SIZE = 1MB,

       MAXSIZE=10,

       FILEGROWTH=1),

      ( NAME = 'MyDB_FG1_Dat2',

       FILENAME =

          'c:\Program Files\Microsoft SQL Server\MSSQL\data\data3.ndf',

       SIZE = 1MB,

       MAXSIZE=10,

       FILEGROWTH=1)

    LOG ON

      ( NAME='MyDB_log',

       FILENAME =

          'c:\Program Files\Microsoft SQL Server\MSSQL\data\data1.ldf',

       SIZE=1,

       MAXSIZE=10,

       FILEGROWTH=1)

    GO

    Have anybody tried to create using SQL-DMO in VB.Net before, plz help me out.


    Best Regards,

    Binu Pappachan

  • Sure. It's not hard. You create the database without the NDF files or the file group, just the basic MDF & LDF file. Then you add the filegroup and files to the database you created. Like this (c#):

    oIndexFile.Name = txtDbName.Text + "_Data_2";

    oIndexFile.PhysicalName = txtPath.Text + "\\" + txtDbName.Text + "_Data_2.ndf";

    oIndexFile.PrimaryFile =

    false;

    oIndexFile.Size = 2;

    oIndexFile.FileGrowthType = SQLDMO_GROWTH_TYPE.SQLDMOGrowth_MB;

    oIndexFile.FileGrowth = 50;

    oIndexGroup.Name = "INDEX_GROUP";

    oDb.FileGroups.Add(oIndexGroup);

    oDb.FileGroups.Item("INDEX_GROUP").DBFiles.Add(oIndexFile);

    I think that's what you mean.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply