Avatar of Moiz Saifuddin
Moiz Saifuddin

asked on 

Delete records

Is this delete statement correct as in syntax if wanted to delete all the records 


delete * from <TableName>


Im getting an error on ExecuteNonQuery() and errmessage = "Incorrect syntax near '*'." 





if (rsBackup.RecordCount > 0)
{
stgSQL = "DELETE * FROM SalesTaxCombos";
DbCommand TempCommand = mdlG3Config.gdbTarget.Connection.CreateCommand();
TempCommand.CommandText = stgSQL;
UpgradeHelpers.DB.DbConnectionHelper.ResetCommandTimeOut(TempCommand);
TempCommand.Transaction = UpgradeHelpers.DB.TransactionManager.GetCurrentTransaction(mdlG3Config.gdbTarget.Connection);
TempCommand.ExecuteNonQuery();

Open in new window



SQLDatabases

Avatar of undefined
Last Comment
slightwv (䄆 Netminder)
Avatar of arnold
arnold
Flag of United States of America image

Which sql server?

Delete from <tablename>


This will delete entire rows unless restricts through a where clause.
Avatar of Moiz Saifuddin
Moiz Saifuddin

ASKER

Error message from source "Microsoft OLE DB Provider for SQL Server"
Avatar of Moiz Saifuddin

ASKER

Although in this site below they mention delete * from... as a valid query to delete all the records

https://www.geeksforgeeks.org/sql-delete-statement/?ref=lbp
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
'delete from table' will work but has overhead.  If you want to remove ALL rows, look up truncate:
https://docs.microsoft.com/en-us/sql/t-sql/statements/truncate-table-transact-sql?view=sql-server-ver15
Databases
Databases

Databases are organized collections of data, most commonly accessed through management systems including schemas, tables, queries and processes that allow users to enter and manipulate the information or utilize it in other fashions, such as with web applications or for reporting purposes.

62K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo