Sunday, 5 May 2013

How could i insert the data into my secondary files(.ndf)?


Step 1:- Create a file group with secondary file (.ndf file)

( NAME = N'FileBackupsTest',
FILENAME = N'E:\FileBackupsTest.mdf' ,
SIZE = 5120KB , FILEGROWTH = 5124KB ),
FILEGROUP [SecondaryFile]
( NAME = N'FileBackupsTestUserData1',
FILENAME = N'e:\FileBackupsTestUserData1.ndf' ,
SIZE = 512KB , FILEGROWTH = 512KB )
LOG ON
( NAME = N'FileBackupsTest_log',
FILENAME = N'e:\SQLData\FileBackupsTest_log.ldf' ,
SIZE = 1024KB , FILEGROWTH = 512KB )
GO
USE [FileBackupsTest]
GO

Step 2: create a table with secondary file group name.By default a table created on Primary file (.mdf) file but if you want to enter data into secondory file(.ndf) than mention seondory File group name.
CREATE TABLE Demo
(
name char(12),
city char(12),
roll int
)
ON [secondaryFile]



Step : 3 insert some data into this table and check the size of your secondary file will grow in size. check the size with sp_helpdb 'FileBackupsTest1'
GO and To Find which object resides in which FileGroup in a database, run the below queries.


T-SQL - Find which Object resides in which FileGroup
To Find which object resides in which FileGroup in a database, run the below queries.

/**************** For SQL 2000 ****************/

Select Distinct OBJECT_NAME(SI.id) AS ObjectName
        ,SO.type AS ObjectType
        ,FG.GroupName AS FileGroupName
from sysindexes SI , sysfilegroups FG ,sysobjects SO
where SI.groupid = FG.groupid and
      SI.id = SO.id
Order by ObjectName

/**************** For SQL 2005 and SQL 2008 ****************/

Select Distinct OBJECT_NAME(SI.object_id) AS ObjectName
        ,OBJECTPROPERTYEX(SI.object_id,'BaseType') AS ObjectType
        ,FG.Name AS FileGroupName
from sys.indexes SI , sys.filegroups FG
where SI.data_space_id = FG.data_space_id
Order by ObjectName

No comments:

Post a Comment