Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Partition on #temp table

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2015-01-28 : 17:35:48
when i try to create partition on the temp table im getting the below error:

Msg 1921, Level 16, State 1, Line 32
Invalid partition scheme 'PartitionToPrimary' specified.

code tried:



IF OBJECT_ID('tempdb..#hubbabubba') IS NOT NULL
BEGIN
DROP TABLE #hubbabubba;
END

CREATE TABLE #hubbabubba (
someint INT PRIMARY KEY NONCLUSTERED IDENTITY(1,1)
,somechar VARCHAR(50)
,somedate DATE
,somebit BIT DEFAULT(0))

IF EXISTS (SELECT name FROM sys.partition_schemes WHERE name = 'PartitionToPrimary')
BEGIN
DROP PARTITION SCHEME PartitionToPrimary
END
IF EXISTS (SELECT name FROM sys.partition_functions WHERE name = 'PartitionByMonth')
BEGIN
DROP PARTITION FUNCTION PartitionByMonth
END

CREATE PARTITION FUNCTION PartitionByMonth (DATE)
AS RANGE RIGHT
FOR VALUES ('2014/01/01', '2014/02/01', '2014/03/01', '2014/04/01', '2014/05/01','2014/06/01'
, '2014/07/01', '2014/08/01', '2014/09/01', '2014/10/01', '2014/11/01', '2014/12/01');

CREATE PARTITION SCHEME PartitionToPrimary
AS PARTITION PartitionByMonth
ALL TO ([PRIMARY]);

CREATE CLUSTERED INDEX idx_hubba_somedate ON #hubbabubba (somedate)
ON PartitionToPrimary (somedate);
GO




Can any one help me on this?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-01-28 : 17:37:44
Why are you trying to create a partition on a temp table? There's really no point in that.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2015-01-28 : 18:29:34
We have partition physical table for which we have defind partitioncolumn of stateid and need to truncate only the concern stateid data whenever we received the input parameter from the stored procedure.

so we no need one more physical partition table inorder to move
from main table to another physical partition table instead i can
use #temp partition table.


quote:
Originally posted by tkizer

Why are you trying to create a partition on a temp table? There's really no point in that.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-01-28 : 18:37:08
Just use a regular table to do the move. Or you can check out this discussion: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/e8c1c08e-1211-443e-9c66-1765986787d6/is-it-possible-to-create-partition-on-temp-table-in-sql-server?forum=sqldataaccess

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2015-01-28 : 18:42:26
you mean one more physical table definition with the same partitioning definition as main table has?
quote:
Originally posted by tkizer

Just use a regular table to do the move. Or you can check out this discussion: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/e8c1c08e-1211-443e-9c66-1765986787d6/is-it-possible-to-create-partition-on-temp-table-in-sql-server?forum=sqldataaccess

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-01-28 : 18:52:27
This is what I am saying: CREATE TABLE hubbabubba

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2015-01-28 : 19:02:42
my main objective is not to store multiple table objects in the same database. we have already have 10 partition tables for which now i need to define another 10 partition table. is that your also saying?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-01-28 : 19:39:52
But aren't you using a temp table because you are moving data around? Isn't it a one-time process? If you are dead set on using a # table, then check out the link I posted.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -