Just to be sure, an index "rebuild" won't do a move. It must be a CREATE INDEX that matches the currently existing index in all ways and it must have the WITH(DROP_EXISTING=ON) option and it must contain the ON filegroup option to move it to the file group of choice.
Please take the time to lookup the DROP_EXISTING option in the CREATE INDEX documentation.
https://learn.microsoft.com/en-us/sql/t-sql/statements/create-index-transact-sql
--Jeff Moden
Change is inevitable... Change for the better is not.
November 28, 2022 at 8:18 pm
Adding another post just to make the forum software actually see 2 pages of posts.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 28, 2022 at 10:39 pm
Just so I understand I just need to rebuild Index with:
CREATE UNIQUE CLUSTERED INDEX PK__UserLog__7F8B815172CE9EAE ON UserLog (UserLogID) WITH (DROP_EXISTING = ON) ON HISTORY
Thx.
That's it. No need to drop any constraints, etc. If you're in the Bulk_logged Recovery Models, it'll be Minimally Logged, as well. Just remember that you that you can't do that if you're doing replication, etc. And take a logfile backup immediately before and after using that command.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 28, 2022 at 10:47 pm
BTW... it's a really good habit to add brackets to the name of the file group. It'll let you live for HISTORY without them but it's absolutely required if the file group is [PRIMARY]. So the ON HISTORY part of your code should be ON [HISTORY] just to develop a safe habit. It's one of the few places where things like that are sometimes required.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 28, 2022 at 10:53 pm
As a bit of a future-planning sidebar...
If that table ever becomes fragmented, you may want to someday defragment it. To keep the file group from having a whole bunch of wasted space after doing doing such a thing, here's what I do (and I'll use HISTORY in my example.
Of course, that can be automated with a stored procedure.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 29, 2022 at 12:51 am
Thanks Jeff .. by default, will all sorting be done in tempdb during Index creation?
November 29, 2022 at 3:20 am
Thanks Jeff .. by default, will all sorting be done in tempdb during Index creation?
It took you longer to post the question than it would for you to look it up. You have to learn to look stuff like this up. Lookup CREATE INDEX and then search for "tempdb" in that documenation.
Then try it out and let us know. 😉 I know the answer but want to see if you'll come to the right conclusion.
I'm not saying that to be snarky or mean. You need to learn to look stuff up instead of relying on the kindness of strangers. It will make you much more valuable to your company. Where there's perceived value, there's normally some $$$ in the form of an annual increase. Higher performances get a bigger chunk of the bonus pie.
As a bit of a sidebar, I don't want big tables to sort in tempdb. I want to save tempdb for other stuff that is running at the same time. Others will have a different opinion/recommendation but mine is, leave tempdb alone for stuff like this.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 29, 2022 at 6:00 pm
This was removed by the editor as SPAM
November 29, 2022 at 6:01 pm
This was removed by the editor as SPAM
Viewing 9 posts - 16 through 23 (of 23 total)
You must be logged in to reply to this topic. Login to reply