Solved

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

Posted on 2011-02-16
5
419 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now