Getting errors while truncating Partitioned Table using SQL Server 2012












1














I am just doing some POC on table partitioning on existing tables, but I am stuck at this level, when I run the script shown below. Please give me suggestions



TRUNCATE TABLE [AdventureWorks2012].[dbo].[SalesOrderDetail_DataNEW] 
WITH (PARTITION (3));


I am getting an error like:




Msg 319, Level 15, State 1, Line 2

Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.











share|improve this question
























  • What version of SQL Server, and what's the compatibility level of your database? Truncating partitions is supported only from SQL Server 2016 onwards. (Even then, the correct syntax uses PARTITIONS, but the error message here suggests you're just on an earlier version/compat level).
    – Jeroen Mostert
    Nov 19 '18 at 14:05












  • Sql server 2012
    – Sreenu131
    Nov 19 '18 at 14:06






  • 2




    Right, just saw it in the title. :-P Well, there's your answer in any case -- SQL Server 2012 does not support this. At best you can ALTER TABLE SWITCH the partition, truncate, and switch back.
    – Jeroen Mostert
    Nov 19 '18 at 14:07










  • @JeroenMostert Thank you for the information i have been thinking only on syntactical error .i didn't think about version compatibility
    – Sreenu131
    Nov 19 '18 at 14:09
















1














I am just doing some POC on table partitioning on existing tables, but I am stuck at this level, when I run the script shown below. Please give me suggestions



TRUNCATE TABLE [AdventureWorks2012].[dbo].[SalesOrderDetail_DataNEW] 
WITH (PARTITION (3));


I am getting an error like:




Msg 319, Level 15, State 1, Line 2

Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.











share|improve this question
























  • What version of SQL Server, and what's the compatibility level of your database? Truncating partitions is supported only from SQL Server 2016 onwards. (Even then, the correct syntax uses PARTITIONS, but the error message here suggests you're just on an earlier version/compat level).
    – Jeroen Mostert
    Nov 19 '18 at 14:05












  • Sql server 2012
    – Sreenu131
    Nov 19 '18 at 14:06






  • 2




    Right, just saw it in the title. :-P Well, there's your answer in any case -- SQL Server 2012 does not support this. At best you can ALTER TABLE SWITCH the partition, truncate, and switch back.
    – Jeroen Mostert
    Nov 19 '18 at 14:07










  • @JeroenMostert Thank you for the information i have been thinking only on syntactical error .i didn't think about version compatibility
    – Sreenu131
    Nov 19 '18 at 14:09














1












1








1







I am just doing some POC on table partitioning on existing tables, but I am stuck at this level, when I run the script shown below. Please give me suggestions



TRUNCATE TABLE [AdventureWorks2012].[dbo].[SalesOrderDetail_DataNEW] 
WITH (PARTITION (3));


I am getting an error like:




Msg 319, Level 15, State 1, Line 2

Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.











share|improve this question















I am just doing some POC on table partitioning on existing tables, but I am stuck at this level, when I run the script shown below. Please give me suggestions



TRUNCATE TABLE [AdventureWorks2012].[dbo].[SalesOrderDetail_DataNEW] 
WITH (PARTITION (3));


I am getting an error like:




Msg 319, Level 15, State 1, Line 2

Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.








sql sql-server tsql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 15:53









Rahul Neekhra

6021627




6021627










asked Nov 19 '18 at 13:50









Sreenu131

1,340138




1,340138












  • What version of SQL Server, and what's the compatibility level of your database? Truncating partitions is supported only from SQL Server 2016 onwards. (Even then, the correct syntax uses PARTITIONS, but the error message here suggests you're just on an earlier version/compat level).
    – Jeroen Mostert
    Nov 19 '18 at 14:05












  • Sql server 2012
    – Sreenu131
    Nov 19 '18 at 14:06






  • 2




    Right, just saw it in the title. :-P Well, there's your answer in any case -- SQL Server 2012 does not support this. At best you can ALTER TABLE SWITCH the partition, truncate, and switch back.
    – Jeroen Mostert
    Nov 19 '18 at 14:07










  • @JeroenMostert Thank you for the information i have been thinking only on syntactical error .i didn't think about version compatibility
    – Sreenu131
    Nov 19 '18 at 14:09


















  • What version of SQL Server, and what's the compatibility level of your database? Truncating partitions is supported only from SQL Server 2016 onwards. (Even then, the correct syntax uses PARTITIONS, but the error message here suggests you're just on an earlier version/compat level).
    – Jeroen Mostert
    Nov 19 '18 at 14:05












  • Sql server 2012
    – Sreenu131
    Nov 19 '18 at 14:06






  • 2




    Right, just saw it in the title. :-P Well, there's your answer in any case -- SQL Server 2012 does not support this. At best you can ALTER TABLE SWITCH the partition, truncate, and switch back.
    – Jeroen Mostert
    Nov 19 '18 at 14:07










  • @JeroenMostert Thank you for the information i have been thinking only on syntactical error .i didn't think about version compatibility
    – Sreenu131
    Nov 19 '18 at 14:09
















What version of SQL Server, and what's the compatibility level of your database? Truncating partitions is supported only from SQL Server 2016 onwards. (Even then, the correct syntax uses PARTITIONS, but the error message here suggests you're just on an earlier version/compat level).
– Jeroen Mostert
Nov 19 '18 at 14:05






What version of SQL Server, and what's the compatibility level of your database? Truncating partitions is supported only from SQL Server 2016 onwards. (Even then, the correct syntax uses PARTITIONS, but the error message here suggests you're just on an earlier version/compat level).
– Jeroen Mostert
Nov 19 '18 at 14:05














Sql server 2012
– Sreenu131
Nov 19 '18 at 14:06




Sql server 2012
– Sreenu131
Nov 19 '18 at 14:06




2




2




Right, just saw it in the title. :-P Well, there's your answer in any case -- SQL Server 2012 does not support this. At best you can ALTER TABLE SWITCH the partition, truncate, and switch back.
– Jeroen Mostert
Nov 19 '18 at 14:07




Right, just saw it in the title. :-P Well, there's your answer in any case -- SQL Server 2012 does not support this. At best you can ALTER TABLE SWITCH the partition, truncate, and switch back.
– Jeroen Mostert
Nov 19 '18 at 14:07












@JeroenMostert Thank you for the information i have been thinking only on syntactical error .i didn't think about version compatibility
– Sreenu131
Nov 19 '18 at 14:09




@JeroenMostert Thank you for the information i have been thinking only on syntactical error .i didn't think about version compatibility
– Sreenu131
Nov 19 '18 at 14:09












1 Answer
1






active

oldest

votes


















0














The name of your table is wrong --



Here is a syntax diagram



[ { database_name .[ schema_name ] . | schema_name . } ]  
table_name


add the database and table name to that schema name or take out the brackets



here is the current documentation location
https://docs.microsoft.com/en-us/sql/t-sql/statements/truncate-table-transact-sql?view=sql-server-2017






share|improve this answer





















  • Hi I changed the script as you suggested but still i am getting the same error .Thanks for the quick response sir
    – Sreenu131
    Nov 19 '18 at 14:02












  • @Sreenu131 -- yep makes sense.. if you read the documentation on the link it seems the WITH part is only supported in versions after 2016
    – Hogan
    Nov 19 '18 at 20:13











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',
autoActivateHeartbeat: false,
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%2f53376074%2fgetting-errors-while-truncating-partitioned-table-using-sql-server-2012%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The name of your table is wrong --



Here is a syntax diagram



[ { database_name .[ schema_name ] . | schema_name . } ]  
table_name


add the database and table name to that schema name or take out the brackets



here is the current documentation location
https://docs.microsoft.com/en-us/sql/t-sql/statements/truncate-table-transact-sql?view=sql-server-2017






share|improve this answer





















  • Hi I changed the script as you suggested but still i am getting the same error .Thanks for the quick response sir
    – Sreenu131
    Nov 19 '18 at 14:02












  • @Sreenu131 -- yep makes sense.. if you read the documentation on the link it seems the WITH part is only supported in versions after 2016
    – Hogan
    Nov 19 '18 at 20:13
















0














The name of your table is wrong --



Here is a syntax diagram



[ { database_name .[ schema_name ] . | schema_name . } ]  
table_name


add the database and table name to that schema name or take out the brackets



here is the current documentation location
https://docs.microsoft.com/en-us/sql/t-sql/statements/truncate-table-transact-sql?view=sql-server-2017






share|improve this answer





















  • Hi I changed the script as you suggested but still i am getting the same error .Thanks for the quick response sir
    – Sreenu131
    Nov 19 '18 at 14:02












  • @Sreenu131 -- yep makes sense.. if you read the documentation on the link it seems the WITH part is only supported in versions after 2016
    – Hogan
    Nov 19 '18 at 20:13














0












0








0






The name of your table is wrong --



Here is a syntax diagram



[ { database_name .[ schema_name ] . | schema_name . } ]  
table_name


add the database and table name to that schema name or take out the brackets



here is the current documentation location
https://docs.microsoft.com/en-us/sql/t-sql/statements/truncate-table-transact-sql?view=sql-server-2017






share|improve this answer












The name of your table is wrong --



Here is a syntax diagram



[ { database_name .[ schema_name ] . | schema_name . } ]  
table_name


add the database and table name to that schema name or take out the brackets



here is the current documentation location
https://docs.microsoft.com/en-us/sql/t-sql/statements/truncate-table-transact-sql?view=sql-server-2017







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 13:55









Hogan

54.4k864102




54.4k864102












  • Hi I changed the script as you suggested but still i am getting the same error .Thanks for the quick response sir
    – Sreenu131
    Nov 19 '18 at 14:02












  • @Sreenu131 -- yep makes sense.. if you read the documentation on the link it seems the WITH part is only supported in versions after 2016
    – Hogan
    Nov 19 '18 at 20:13


















  • Hi I changed the script as you suggested but still i am getting the same error .Thanks for the quick response sir
    – Sreenu131
    Nov 19 '18 at 14:02












  • @Sreenu131 -- yep makes sense.. if you read the documentation on the link it seems the WITH part is only supported in versions after 2016
    – Hogan
    Nov 19 '18 at 20:13
















Hi I changed the script as you suggested but still i am getting the same error .Thanks for the quick response sir
– Sreenu131
Nov 19 '18 at 14:02






Hi I changed the script as you suggested but still i am getting the same error .Thanks for the quick response sir
– Sreenu131
Nov 19 '18 at 14:02














@Sreenu131 -- yep makes sense.. if you read the documentation on the link it seems the WITH part is only supported in versions after 2016
– Hogan
Nov 19 '18 at 20:13




@Sreenu131 -- yep makes sense.. if you read the documentation on the link it seems the WITH part is only supported in versions after 2016
– Hogan
Nov 19 '18 at 20:13


















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%2f53376074%2fgetting-errors-while-truncating-partitioned-table-using-sql-server-2012%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

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith