Solved

Moving the 49 GB of tbl from one drive to another drive

Posted on 2011-02-16
5
425 Views
Last Modified: 2012-05-11
We have to move one table of 49 GB which I need to move  to another drive as the data file in the drive is consuming the space. The Primary datafile is about 500 GB. All the tables in the data file is partitioned according to partition schema based on the datekey. Can I move each table from one drive (H) to other drive  i.e to E drive from the primary file group to different/ secondary file group by creating different file groups.

Do we get any issues/problems if I move the table to another file group and simulataneously changing the location of the drive? Is it possible. But I tested in the Test env for smaller tables but I donno for the table of that size will it work or not because we gonna do it in PROD so anything goes wrong I'll be in danger.

Create a new file group with the secondary file group

ALTER DATABASE MC
ADD FILEGROUP [SAPROWCOUNT]

--Specify the location for the filegroup

ALTER DATABASE MC
ADD FILE
( NAME = SAPROWCount,
FILENAME = 'E:\ SAPROWCount_Secondary.ndf',
SIZE = 500 MB,         --- depends on the requirement
MAXSIZE = Unlimited,---depends on the requirement
FILEGROWTH = 10%)     ---depends on the requirement
TO FILEGROUP [SAPROWCOUNT]
GO

--Drop the constraint on the count table

ALTER TABLE [SAPROWCount]
DROP CONSTRAINT [SAPROWCount] WITH (MOVE TO SAPROWCOUNT)




--Adding the constraint to the primary clustered key to the table

ALTER TABLE [SAPROWCount]
ADD CONSTRAINT [PKSAPROWCount] PRIMARY KEY CLUSTERED
(   UserAgentKey ASC,
     PageUrlKey ASC,
       InternalSource ASC,
       DateKey ASC,
       EventDateKey  ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [SAPROWCOUNT]

--Adding the constraints to the table

ALTER TABLE [dbo].[SAPROWCount]  WITH CHECK ADD  CONSTRAINT [FKSAPROWCountPageUrl] FOREIGN KEY([PageUrlKey])
REFERENCES [dbo].[DimPageUrl] ([PageUrlKey])
GO


ALTER TABLE [dbo].[FACTSAPROWCount]
CHECK CONSTRAINT [FKFACT SAPROWCountUserAgent]
GO

COUld you please verify if this script wrks fine or any suggestions would help me

Waiting for your reply.

Thanks,
0
Comment
Question by:srionline2k6
5 Comments
 
LVL 16

Expert Comment

by:EvilPostIt
ID: 34914176
Sounds like the same process which sprang to mind for me. Test it with another database on a test machine to ensure the code will work.
0
 
LVL 20

Expert Comment

by:Marten Rune
ID: 34958219
Can I move each table from one drive (H) to other drive  i.e to E drive from the primary file group to different/ secondary file group by creating different file groups.
ANSWER: YES

Do we get any issues/problems if I move the table to another file group and simulataneously changing the location of the drive?
ANSWER: No issues I know of

This is a standard database design, nothing out of the ordinary, except for the size of the table. I would make sure backup exist before. Test their integrity with restore verify only on a second system and your'e ready to go. Make sure you have a maintenancewindow big enough.

//Marten
0
 
LVL 38

Accepted Solution

by:
Jim P. earned 125 total points
ID: 34976613
I would change this
ADD FILE
( NAME = SAPROWCount,
FILENAME = 'E:\ SAPROWCount_Secondary.ndf',
SIZE = 500 MB,         --- depends on the requirement
MAXSIZE = Unlimited,---depends on the requirement
FILEGROWTH = 10%)     ---depends on the requirement
TO FILEGROUP [SAPROWCOUNT]

Open in new window

to this:
ADD FILE
( NAME = SAPROWCount,
FILENAME = 'E:\ SAPROWCount_Secondary.ndf',
SIZE = 40GB,         --- depends on the requirement
MAXSIZE = Unlimited,---depends on the requirement
FILEGROWTH = 2GB)     ---depends on the requirement
TO FILEGROUP [SAPROWCOUNT]

Open in new window


Percent of file growth is a bad idea. Especially when you have a database that can take data loads.

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question