Solved

Regarding Filegroup( table prtition) in ms sql server

Posted on 2010-09-24
2
338 Views
Last Modified: 2012-08-14
Hi,

I want to create t-sql job for automatic creating of new ndf file and automatic dropping/removing same ndf file  based on input parameter (ID and number of rows).  Is it possible in sql server?

I want to add below scripts and conditions in t-sql job:
/*Craete New File Group*/
ALTER DATABASE USERDB Add FileGroup FG_ID
GO

/*Step 2: Add Files to New File Group*/
ALTER DATABASE USERDB
ADD FILE
(
    NAME = [FILE_ID],
    FILENAME = 'C:\SecFiles\ID.ndf',
    SIZE = 5MB    
)
TO FILEGROUP FG_ID;
GO

/*Step 3: Creating a Partition Range Function*/
CREATE PARTITION FUNCTION IDRangePFN (int)
AS RANGE LEFT FOR VALUES
(10,20,30,40,50,60,70)
GO

/*Step 4: Creating a Partition Scheme*/
CREATE PARTITION SCHEME IDRangePS
AS PARTITION IDRangePFN
TO (FG_ID,[PRIMARY])
GO

Condition:
If  id=21 and number of rows (if rowcount=0)---drop ndf file
If  id=21 and number of rows (if rowcount<>0)---no drop ndf file.

after above condition

again creating new table partition function,.schema, range.....

If  id=43 and number of rows (if rowcount=0)---drop ndf file
If   id=43 and number of rows (if rowcount<>0)---no drop ndf file.

Is it possible using t-sql proc?

regards,
Sridhar G









0
Comment
Question by:srinivas_ganamur
2 Comments
 
LVL 23

Accepted Solution

by:
Racim BOUDJAKDJI earned 500 total points
ID: 33753855
<<Is it possible using t-sql proc?>>
Yes.  Yo will need to use dynamic SQL.  Keep in mind the following issue: if aligning the physical storage pruning with logical partition pruning, I would avoid thinking in terms of number of rows but rather think in terms of OS IO ressources. Having a new files created in function of partition ca be quite cumbersome to manage.

Hope this helps...
0
 

Author Closing Comment

by:srinivas_ganamur
ID: 33777528
--
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

708 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

15 Experts available now in Live!

Get 1:1 Help Now