Explicit conversion of column in Table Partition in SQL Server











up vote
0
down vote

favorite












I have table like below:



  CREATE TABLE [dbo].[PartitionExample]
(
[dateTimeColumn1] [datetime] NOT NULL,
CONSTRAINT [PK_PartitionExample] PRIMARY KEY CLUSTERED
(
[dateTimeColumn1] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


I have created Partition Function like below:



  CREATE PARTITION FUNCTION DateRangePF (INT)
AS RANGE RIGHT FOR VALUES ( 20180601,20180901,20181201,20190301)


Then, I have created Partition Scheme for it:



  CREATE PARTITION SCHEME DateRangePS
AS PARTITION DateRangePF TO
(FG032018_SampleDB,FG062018_SampleDB,FG092018_SampleDB,
FG122018_SampleDB,FG032019_SampleDB);


Now, When I am applying the partition scheme to this table, I want to apply explicit conversion of [dateTimeColumn1] column of datetime data type to INT Data Type. But when I tried it, I got syntax error:



 ALTER TABLE [dbo].[PartitionExample] ADD  
CONSTRAINT [PK_PartitionExample] PRIMARY KEY CLUSTERED
(
dateTimeColumn1 ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS =
ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90)
ON DateRangePS(
convert(INT, CONVERT(CHAR(8), dateTimeColumn1, 112));


Can you guys please let me know




  1. how explicit conversion can be implemented in such scenarios.

  2. Also would it perform better when I will perform explicit conversion of datetime column or char(8) column to INT Column for partition.
    Thank you for your help.










share|improve this question
























  • Why not just use the correct data type (which by preference these days would be datetime2 not datetime) for everything, rather than weirdly trying to work with ints?
    – Damien_The_Unbeliever
    Nov 20 at 7:33










  • Well, we thought it would perform better when we will typecast from datetime column to INT column. Also, we have char(8) column in some other table based on which we will apply partition.
    – Murali Dhar Darshan
    Nov 20 at 7:38















up vote
0
down vote

favorite












I have table like below:



  CREATE TABLE [dbo].[PartitionExample]
(
[dateTimeColumn1] [datetime] NOT NULL,
CONSTRAINT [PK_PartitionExample] PRIMARY KEY CLUSTERED
(
[dateTimeColumn1] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


I have created Partition Function like below:



  CREATE PARTITION FUNCTION DateRangePF (INT)
AS RANGE RIGHT FOR VALUES ( 20180601,20180901,20181201,20190301)


Then, I have created Partition Scheme for it:



  CREATE PARTITION SCHEME DateRangePS
AS PARTITION DateRangePF TO
(FG032018_SampleDB,FG062018_SampleDB,FG092018_SampleDB,
FG122018_SampleDB,FG032019_SampleDB);


Now, When I am applying the partition scheme to this table, I want to apply explicit conversion of [dateTimeColumn1] column of datetime data type to INT Data Type. But when I tried it, I got syntax error:



 ALTER TABLE [dbo].[PartitionExample] ADD  
CONSTRAINT [PK_PartitionExample] PRIMARY KEY CLUSTERED
(
dateTimeColumn1 ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS =
ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90)
ON DateRangePS(
convert(INT, CONVERT(CHAR(8), dateTimeColumn1, 112));


Can you guys please let me know




  1. how explicit conversion can be implemented in such scenarios.

  2. Also would it perform better when I will perform explicit conversion of datetime column or char(8) column to INT Column for partition.
    Thank you for your help.










share|improve this question
























  • Why not just use the correct data type (which by preference these days would be datetime2 not datetime) for everything, rather than weirdly trying to work with ints?
    – Damien_The_Unbeliever
    Nov 20 at 7:33










  • Well, we thought it would perform better when we will typecast from datetime column to INT column. Also, we have char(8) column in some other table based on which we will apply partition.
    – Murali Dhar Darshan
    Nov 20 at 7:38













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have table like below:



  CREATE TABLE [dbo].[PartitionExample]
(
[dateTimeColumn1] [datetime] NOT NULL,
CONSTRAINT [PK_PartitionExample] PRIMARY KEY CLUSTERED
(
[dateTimeColumn1] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


I have created Partition Function like below:



  CREATE PARTITION FUNCTION DateRangePF (INT)
AS RANGE RIGHT FOR VALUES ( 20180601,20180901,20181201,20190301)


Then, I have created Partition Scheme for it:



  CREATE PARTITION SCHEME DateRangePS
AS PARTITION DateRangePF TO
(FG032018_SampleDB,FG062018_SampleDB,FG092018_SampleDB,
FG122018_SampleDB,FG032019_SampleDB);


Now, When I am applying the partition scheme to this table, I want to apply explicit conversion of [dateTimeColumn1] column of datetime data type to INT Data Type. But when I tried it, I got syntax error:



 ALTER TABLE [dbo].[PartitionExample] ADD  
CONSTRAINT [PK_PartitionExample] PRIMARY KEY CLUSTERED
(
dateTimeColumn1 ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS =
ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90)
ON DateRangePS(
convert(INT, CONVERT(CHAR(8), dateTimeColumn1, 112));


Can you guys please let me know




  1. how explicit conversion can be implemented in such scenarios.

  2. Also would it perform better when I will perform explicit conversion of datetime column or char(8) column to INT Column for partition.
    Thank you for your help.










share|improve this question















I have table like below:



  CREATE TABLE [dbo].[PartitionExample]
(
[dateTimeColumn1] [datetime] NOT NULL,
CONSTRAINT [PK_PartitionExample] PRIMARY KEY CLUSTERED
(
[dateTimeColumn1] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


I have created Partition Function like below:



  CREATE PARTITION FUNCTION DateRangePF (INT)
AS RANGE RIGHT FOR VALUES ( 20180601,20180901,20181201,20190301)


Then, I have created Partition Scheme for it:



  CREATE PARTITION SCHEME DateRangePS
AS PARTITION DateRangePF TO
(FG032018_SampleDB,FG062018_SampleDB,FG092018_SampleDB,
FG122018_SampleDB,FG032019_SampleDB);


Now, When I am applying the partition scheme to this table, I want to apply explicit conversion of [dateTimeColumn1] column of datetime data type to INT Data Type. But when I tried it, I got syntax error:



 ALTER TABLE [dbo].[PartitionExample] ADD  
CONSTRAINT [PK_PartitionExample] PRIMARY KEY CLUSTERED
(
dateTimeColumn1 ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS =
ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90)
ON DateRangePS(
convert(INT, CONVERT(CHAR(8), dateTimeColumn1, 112));


Can you guys please let me know




  1. how explicit conversion can be implemented in such scenarios.

  2. Also would it perform better when I will perform explicit conversion of datetime column or char(8) column to INT Column for partition.
    Thank you for your help.







sql-server database-design data-partitioning






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 7:23

























asked Nov 20 at 7:12









Murali Dhar Darshan

808




808












  • Why not just use the correct data type (which by preference these days would be datetime2 not datetime) for everything, rather than weirdly trying to work with ints?
    – Damien_The_Unbeliever
    Nov 20 at 7:33










  • Well, we thought it would perform better when we will typecast from datetime column to INT column. Also, we have char(8) column in some other table based on which we will apply partition.
    – Murali Dhar Darshan
    Nov 20 at 7:38


















  • Why not just use the correct data type (which by preference these days would be datetime2 not datetime) for everything, rather than weirdly trying to work with ints?
    – Damien_The_Unbeliever
    Nov 20 at 7:33










  • Well, we thought it would perform better when we will typecast from datetime column to INT column. Also, we have char(8) column in some other table based on which we will apply partition.
    – Murali Dhar Darshan
    Nov 20 at 7:38
















Why not just use the correct data type (which by preference these days would be datetime2 not datetime) for everything, rather than weirdly trying to work with ints?
– Damien_The_Unbeliever
Nov 20 at 7:33




Why not just use the correct data type (which by preference these days would be datetime2 not datetime) for everything, rather than weirdly trying to work with ints?
– Damien_The_Unbeliever
Nov 20 at 7:33












Well, we thought it would perform better when we will typecast from datetime column to INT column. Also, we have char(8) column in some other table based on which we will apply partition.
– Murali Dhar Darshan
Nov 20 at 7:38




Well, we thought it would perform better when we will typecast from datetime column to INT column. Also, we have char(8) column in some other table based on which we will apply partition.
– Murali Dhar Darshan
Nov 20 at 7:38

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387955%2fexplicit-conversion-of-column-in-table-partition-in-sql-server%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387955%2fexplicit-conversion-of-column-in-table-partition-in-sql-server%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Feedback on college project

Futebolista

Albești (Vaslui)