How To Move Existing Table Into A Different Filegroup Using Tsql Script

Jul 12, 2006

Hi,

How to move existing table(include its constraint and index) into a different filegroup using tsql in Sql Server 2000. We have 1000+ tables in our system and we are planning to move around 500 tables to a new file group, which is available on another SAN drive.

Regards.
Sankar N

View 1 Replies


ADVERTISEMENT

Move Table To Different Filegroup

Oct 28, 2005

I will be moving production SQL databases (one is 25Gb, the other is 3Gb) to a new server. One of the reasons is the old server has only IDE disks while the new has raid (I don't know the configuration yet).
Database 1 has a primary and one other filegroup. I want to spread the disk I/O by moving table A to it's own filegroup on it's own disk.
For the purposes of testing I have
1. brought a database onto a test server (using sp_detach_db, copying the files and attaching using sp_attach_db)
2. created a new filegroup
3. created a physical file on disk, allocated space and associated with my new filegroup

my question is how do I now move table A into this file?

View 1 Replies View Related

Move Table To Other Filegroup?

Jul 8, 2004

Hi every body,

Is there anyone know the way to move a table with data to other file group?

View 3 Replies View Related

Move Table To Different Filegroup

Dec 9, 2007

SQl experts and gurus:

How to move tables to the new filegroup which i created. suppose my database has only primary FG and after that i added one FG and due to performance reasons i want to move the existing table to NEW FG.
Thanks.

View 20 Replies View Related

How To Change An Existing Table From A Filegroup To A Partition

May 21, 2008

I've create a partition function and a partion scheme for my database.
Now I would like to change an existing table to use these partition.
The table is replicated.
How can I do this?


Thanks
Markus

View 2 Replies View Related

I Want To Move An Existing Table From Another

May 28, 2007

I want to move an existing table from another.
Example
B.mdf  dbo.xx   to C.mdf  dbo.xx
B.mdf dbo.xx   has records   -  I created a script and install the script for C.mdf dbo.xx  
C.mdf dbo.xx  is empty - 
All I need now is to populate the records from B.mdf dbo.xx to the empty  C.mdf  dbo.xx
I was telling I could do a cut and paste to copy the dbo.xx  
Thank you in advance.
~  Peaches ~

View 4 Replies View Related

How To Move A PK Index Into Another Filegroup

May 22, 2007

Hello,



I have an PK Clustered index that I would like to move to another filegroup, which will inturn reside on another drive. Can someone point me to sql tsql or somewhere on bol that has the step by step on how to accomplish this? Thanks in advance.



John

View 1 Replies View Related

Move Data Between Datafile In Same Filegroup

Jan 28, 2008



Hi all

I've found this problem working with a VLDB, six month ago when I install the DBMS (Win2k3 x64+sp2, SQL 2k5 x64 +sp2, 4 dual core processor and 12 GbRAM) I've got 10 disk (actually ten LUN from a Storage Area Network), each 50Gb.
I've put TempDB and Transaction Log on two separate 50 Gb disk and put the database on 8 different data file on the 8 disk; I've created each datafile with a size of 50 Gb (autogrowth disable), so my DB has 400Gb space in it's datafile.
After a while the datafile began to fill and we decide to add a couple more 50Gb disk where I decide to put to new datafile; now my db is around 430 Gb and I've got this strange situation:


The first 8 datafile now are almost full of data, and obviously they can't growth since they already occupy the whole disk.

The two additional datafile are relatively empty (about 15 Gb each).

As far as I understand now each time that SQL should write to the databse it writes only on the 2 new datafile, and I fear that this can affect performance.
I'd like to reorganize the space in order to have 10 datafile, each with 43Gb of data, but I didn't find any instruction/tool able to move data between datafile.

Anyone has any hint ?

Thank you in advance for any suggestion
Stefano


View 5 Replies View Related

How To Move Internal Tables To Another Filegroup

May 25, 2007

I mange several large databases with multiple files and filegroups. During some maintenance I was trying to remove a filegroup and its files and noticed that I was unable to. It appears that some service broker objects were created on my user defined filegroup.

Looking at the system tables I see several system tables on my user defined filegroup

SELECT o.name +'.' +i.name FROM sysobjects o inner join sysindexes i on i.id = o.id where groupid = 2

queue_messages_1255675521.queue_clustered_index
queue_messages_1255675521.queue_secondary_index
queue_messages_1287675635.queue_clustered_index
queue_messages_1287675635.queue_secondary_index
queue_messages_1319675749.queue_clustered_index
queue_messages_1319675749.queue_secondary_index

my normal tricks do not work as I am unable to even select from these tables.

How to I move them or get rid of them. I am not even sure what is created them as we are not using service broker in our application.

View 3 Replies View Related

SQL 2012 :: How To Add New Filegroup To Existing Partition Scheme

Jul 10, 2014

How to add some more ranges to existing partition schema and function?

Already My table partitioned on date ranges,

6 partitions , each partition contains 6 moths data, so total data is 3 years.

i.e. 1 partition data- from jan2012 to Jun2012
2 partition data- from july2012 to dec2012
3 partition data- from jan2013 to Jun2013
4 partition data- from july2013 to dec2013
5 partition data- from jan2014 to Jun2014
6 partition data- from july2014 to dec2014
After Jan2015 data will go to Primary file group(Default)

Now customer wants to add two more file groups with these partitions ranges, i.e. jan2015 to jun15 and Jul15 to dec15.

File group and ndf file adding is OK, But

how to alter partition scheme and partition function with these additional ranges to existing partition function and scheme?

partitioned table size is 200 GB.

View 1 Replies View Related

SQL Server Admin 2014 :: Move Text Data From Primary To New Filegroup?

Oct 15, 2015

I need to modify a table to reside on a new filegroup and also point TEXTIMAGE_ON to that filegroup instead of PRIMARY. Apparently in the past, the only way to achieve this via SQL is to create a new table, copy over data, drop the old table and rename the new table to the original name. I found this solution in the SQL Server 2005 forum.

Is there any other way to alter this table in order to point the TEXTIMAGE_ON to new filegroup using SQL Server 2014? We are on Standard edition. The technique I am using is the drop constraint (with move option) and add constraint (to new filegroup) commands. The data and indexes move, but not the text data (it still is in primary filegroup).

View 0 Replies View Related

Order Of Data Load And Index Creation / Move Indexes To Separate Filegroup?

Apr 15, 2015

We are running SQL Server 2014 Enterprise Edition (64-Bit) on Windows 2012 R2 Standard (64-Bit).

1. When to create indexes, before or after data is added? Please address Clustered and Non-Clustered Indexes.

2. To move indexes to it's own filegroup, is it best to create the NON-Clustered Indexes on the separate filegroup with code similar to the example below?

CREATE NONCLUSTERED INDEX IX_Employee_OrganizationLevel_OrganizationNode
ON HumanResources.Employee (OrganizationLevel, OrganizationNode)
WITH (DROP_EXISTING = ON)
ON TransactionsFG1;
GO

I have read the following links that states that if you create the Clustered Index on a separate filegroup, it would also move the base table to that particular filegroup. (So I take it that you ONLY can move NON-CLustered Indexes to a separate filegroup.)

Placing Indexes on Filegroups:

[URL]

By default, indexes are stored in the same filegroup as the base table on which the index is created. A nonpartitioned clustered index and the base table always reside in the same filegroup. However, you can do the following:

• Create nonclustered indexes on a filegroup other than the filegroup of the base table.

Move an Existing Index to a Different Filegroup:

[URL]

Limitations and Restrictions

• If a table has a clustered index, moving the clustered index to a new filegroup moves the table to that filegroup.

• You cannot move indexes created using a UNIQUE or PRIMARY KEY constraint using Management Studio. To move these indexes use the CREATE INDEX statement with the (DROP_EXISTING=ON) option in Transact-SQL.

View 1 Replies View Related

Move / Migrate DB's Without Disturbing Existing

Jul 30, 2007

Typically small companies or small projects which use SQL Server / IIS / File Shares / .NET solutions deploy these apps on a single server many times using just one IP address and the NETBIOS name of the server for both IIS / SQL. Many times there is no use of DNS and even when there is everything is mapped to the server/netbios name.

As environments grow and there is a requirement to create an n-tier server setup possible due to new security requirements, extention of the intranet to the internet, or to scale out an application you may need to split IIS / SQL into different servers. The question then becomes how do you do this without affecting existing services and you want to have minimal down time without having to change all connection information within deployed apps until you have time to review the changes carefully.

First let me begin with how to move IIS away from SQL and then I'll discuss the reverse.

The best way I've found to control the move of IIS sites is by assigning each site it's own ip address / dns host record and adding the ip address to the server network card and IIS site. Now each time you need to move 1 or more sites you can simply replicate the site to another server and change the dns ip pointer to the new pointer. If you have existing sites which were not setup in this fashion you can also move them to a new server, create a site with name of the old netbios machine name, and redirect the default web site to this new site.

Now you successfully isolated SQL Server from IIS/.NET apps you can take your time and correct the apps to use the new dns entry in connection strings instead of using the netbios name of the machine. Once you have corrected the app you can turn off any redirection.

Now let's assume you have the opposite scenario where you started off with a small server and your SQL database server now requires a server with more memory / more processors and you want to keep IIS / FileShares were they are and want to move SQL Databases to a new server. As I mentioned above a good way to do this is by setting up each database with it's own dns entry a very effective redirection mechanism. However you are may be inheriting a system which does not employ this mechanism and again uses the default netbios machine name, furthermore this may get more complicated because there may be multiple instances of SQL Server running on different port numbers.
You could use SQL Aliases on the clients to redirect connections to the newly created instances but this would require changing every pc and IIS server and it would be cumbursome to manage. It would have been nice if microsoft provided a way to redirect from the server just like IIS does but they did not. A product which will help you setup a server based redirection of ports 1433/1434 and/or any other ports is called porttunnel by steelbytes.com. Once you've installed the redirecting service on the server all new requests on port the ports selected will be redirected to the new server which I recommend be redirected to their own dns entries and this will buy the applications developer time to change their applications.

I would like to hear any comments or experiences with this that any of you may have had or if anyone has found a better solution. I'm in no way associated with the product / or company mentioned above just found it to be a good solution.

Best Regards,
Valter Borges

View 4 Replies View Related

Methods To Move Existing DTS Packages

Mar 19, 2008

I need to move total of 50 DTS packages from SQL 2000 to SQL 2005.Could someone give me the best way to do this ?

Do I need to just save the package onto the new server OR do I use the DTS package migration wizard.

What are the problems that can arise ?

View 4 Replies View Related

Moving ONE Table To A Different Filegroup Using T-SQL

Aug 29, 2002

I need to know if it is possible to move ONE table from an existing filegroup to another existing filegroup.
The answer I received to use ALTER database only modifies the file/filegroup name or changes the default filegroup.
Any assistance will be greatly appreciated.

View 1 Replies View Related

Locate Table To Filegroup

Sep 18, 2005

I have created a new filegroup,and i want to add existing table to the file group.
I don't have the appropriate syntax for this.

Please Help.

Regards Mr. Mumin
Thanks All,

View 1 Replies View Related

Can I Create A Filegroup On Existnig Table

Feb 22, 2001

Can I create a filegroup on existnig table?If yes,How?
TIA

View 3 Replies View Related

Moving Table(s) To A Different Filegroup In SQL 2005

Oct 2, 2007

Is there anyway to move tables without any indexes to a filegroup?

View 1 Replies View Related

Change Table File Group Filegroup

May 10, 2007

Hi There



I am running SQL Server 2005 Enterprise Edition, i want to split my data and indexes on different drives.



In 2000 i had to recreate clustered indexes and non clustered indexes on the correct filegroups to accomplish this.



In 2005 i see there is a ALTER TABLE MOVE TO Filegroup option, thats cool.



Does this effectively do the same as rebuilding the clustered index on the new filegroup? Will this leave the other indexes of the table on the primay filegroup or move them as well ?



If i wanted to also move the non clustered indexes is there a better way to move them that drop and re-create on the new filegroup in 2005, i see the ALTER INDEX statement does not support a move to filegroup option.



In a nutshell what is the best/easiest way to move exisitng table data and indexes to new file groups in Sql Server 2005 Enterprise Edition?



Thanx

View 10 Replies View Related

SQL Server Admin 2014 :: Filegroup By Table Category

Oct 14, 2015

I'm being asked to create multiple filegroups for a new database based on the table type, transaction, lookup, misc... From what i'm reading this doesn't make sense. I'm reading either large tables get file groups, nonclustered indexes when they are about the same size of the data, or a few other reasons...

First of all, we are talking about the same disk (please don't ask me about how it is configured) and I'm not sure yet if restoring separate file groups is even going to be necessary.

So here are my questions (beyond, the test and see what happens) because in the end I'm going to probably have to do what i'm told. So this is for my professional knowledge.

1. Does file groups separated by table type make sense?
2. Should you put tables that are queried often together in the same or different file groups.
3. I'm pretty sure you can't restore single file group for write access, am I correct?

View 0 Replies View Related

Partitioned View Broken After Moving Table To New Filegroup

Jul 20, 2005

I am using SQL Server 2000, SP3.I created an updatable partitioned view awhile ago and it has beenrunning smoothly for some time. The partition is on a DATETIME columnand it is partitioned by month. Each month a stored procedure isscheduled that creates the new month's table, and alters the view toinclude it. Again... working like a charm for quite some time.This past weekend I moved some of the first tables onto a new filegroup. I did this through Enterprise Manager, by going into designmode for the table, then going into the properties for the table andchanging the file group there as well as in all of the indexes. Nowthe partitioned view is no longer updatable. It gives the errormessage: "UNION ALL view '<view name>' is not updatable because apartitioning column was not found."I have extracted the DDL for all of the partition tables and comparedthem and they all look the same. I checked and then double-checked theCHECK constraints to make sure that they were all valid and they are.If I remove the tables that I moved to the new file group from theview, then it is once again updatable, but when I put them back in itfails again.Any ideas? If you would like samples of the code then I can send italong, but it's rather large, so I have not included it here.Thanks!Thomas R. Hummel

View 3 Replies View Related

DB Engine :: Disadvantage Of Creating A Table In Separate Filegroup

Aug 17, 2015

We have a table that we are using for inserts for every 2mins and it is a very large table.

I am panning to add this table to a separate file and file-group, so that i can keep this file in separate drive.And it will restore files level.

Is there any disadvantage if we create this table in this way.

View 8 Replies View Related

Creating A Common Table Expression--temporary Table--using TSQL???

Jul 23, 2005

Using SQL against a DB2 table the 'with' key word is used todynamically create a temporary table with an SQL statement that isretained for the duration of that SQL statement.What is the equivalent to the SQL 'with' using TSQL? If there is notone, what is the TSQL solution to creating a temporary table that isassociated with an SQL statement? Examples would be appreciated.Thank you!!

View 11 Replies View Related

Clustered Versus Create Table On High Speed FILEGROUP

Nov 30, 2005

Hi,I am expanding our data warehouse solution with new filegroups onseveral subsystems.I want to know which idea is better!- create clustered indexes on tables to 'move' them to new filegroups- create these tables on the new filegroups.The background of this question is as follows:- we want the whole data on the new filegroups- we want to know if there is any difference in performance between the2 solutionsThanks in advance,Danny

View 4 Replies View Related

TSQL Statement Extracting Data From One Table Through Another Table

Nov 17, 2007

Hi,

I have 2 tables,
MembersTemp and Organisations

I'm trying to extract the organisation Name from the organisations table but am unsure of the sql statement to do this.

Initiallt I only have the ExecID for the MembersTemp table

MembersType table:
ExecID 3013
OrganisationID 4550

Organisation table:
ID 4550 (PK)
Name "Microboff"

Any ideas??

View 5 Replies View Related

Query To Move Certian Data From Sql Table To Access Table

Dec 14, 2007

hi all,
is there any query to move certain data from a sql data to access table through query. i am having a requirement where i have to fetch the records from a sql table that falls within a specified range to a ms access table. is this possible through a query.

thanks

View 5 Replies View Related

Transact SQL :: How To Alter Existing Table Column As Identity Without Dropping Table

Nov 20, 2013

I have created a table as below mentioned. Then I want to alter the ID column as identity(1,1) without dropping the table as well as losing the data.

create table dbo.IdentityTest
(
id int not null,
descript varchar(255) null,
T_date datetime not null
)

View 7 Replies View Related

Create An Extra Table (for Audit Purpose) For Every Existing Table In A Database

Mar 28, 2008

Hi all, please help. I m trying to create an "empty" table from existing table for the audit trigger purpose.
For now, i am trying to create an empty audit table for every table in a database named "pubs", and it's seem won't work.
Please advise.. Thanks in advance.

Here is my code:





Code Snippet

USE pubs

DECLARE @TABLE_NAME sysname
DECLARE @AUDIT_TABLE VARCHAR(50)

SELECT @TABLE_NAME= MIN(TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES
WHERE
TABLE_TYPE= 'BASE TABLE'
AND TABLE_NAME NOT LIKE 'audit%'
AND TABLE_NAME!= 'sysdiagrams'
AND TABLE_NAME!= 'Audit'
AND TABLE_NAME = 'sales'

WHILE @TABLE_NAME IS NOT NULL
BEGIN

SELECT @TABLE_NAME= MIN(TABLE_NAME) FROM INFORMATION_SCHEMA.Tables
WHERE TABLE_NAME> @TABLE_NAME
AND TABLE_NAME = 'sales'

SELECT @AUDIT_TABLE = 'Audit'+''@TABLE_NAME''


SELECT * INTO @AUDIT_TABLE
FROM @TABLE_NAME

TRUNCATE TABLE @AUDIT_TABLE
ALTER TABLE @AUDIT_TABLE ADD UserAction Char(10),AuditStartTime Char(50),AuditUser Char(50)


SELECT @TABLE_NAME= MIN(TABLE_NAME) FROM INFORMATION_SCHEMA.Tables
WHERE TABLE_NAME> @TABLE_NAME
AND TABLE_TYPE= 'BASE TABLE'
AND TABLE_NAME!= 'sysdiagrams'
AND TABLE_NAME!= 'Audit'
AND TABLE_NAME NOT LIKE 'audit%'

END
Thanks. ..

View 6 Replies View Related

Copying All Rows From One Table Into Another Existing Table And Overwriting Data

Feb 15, 2005

i have 2 tables (both containing the same column names/datatypes), say table1 and table2.. table1 is the most recent, but some rows were deleted on accident.. table2 was a backup that has all the data we need, but some of it is old, so what i want to do is overwrrite the rows in table 2 that also exist in table 1 with the table 1 rows, but the rows in table 2 that do not exist in table one, leave those as is.. both tables have a primary key, user_id.

any ideas on how i could do this easily?

thanks

View 1 Replies View Related

Tempoary Table Question - How To Create One With The Same Schema As An Existing Table?

Jul 28, 2006

Hello,

I'd like to create a temporary table with the same schema as an exiting table. How can I do this without hard coding the column definitions into the temporary table definition?

I'd like to do something like:

CREATE TABLE #tempTable LIKE anotherTable

..instead of...

CREATE TABLE #tempTable (id INT PRIMARY KEY, created DATETIME NULL etc...

I'm sure there must be a simple way to do this!

Many thanks,

Ben S

View 3 Replies View Related

TSQL - If Using INTO , Where Should I Look For The Table?

Sep 6, 2007

Hi guys,
If I use the script below, where can I find the table "myTable"?
(I need to see the results of the query)
Thanks in advance,
Aldo.




Code Snippet
SELECT MyTable.MyField
INTO MyTable
FROM MyTable




View 8 Replies View Related

SQL 2012 :: Importing Excel Table Into Existing Table?

Aug 25, 2014

I am using the DTS wizard and having problems importing excel into an existing table.

Problem is that various column in excel are defined as double in the wizard but in my db table it is defined as an integer.

How do I get around this issue so the data types in excel can match up accordingly to my defined data type in my db table?

The wizard does a bad job of guessing the correct data type.

I have heard of using a staging table to import from excel and using that as my source to import into my existing table.

View 8 Replies View Related

How To Rename A Table With TSQL?

Aug 8, 2001

Does anyone know how to rename a table with TSQL? I want to automate the renaming of a table.

-Matt

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved