Getting errors while truncating Partitioned Table using SQL Server 2012
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

add a comment |
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

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 usesPARTITIONS
, 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 canALTER 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
add a comment |
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

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

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 usesPARTITIONS
, 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 canALTER 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
add a comment |
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 usesPARTITIONS
, 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 canALTER 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
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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