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();
ASKER
Error message from source "Microsoft OLE DB Provider for SQL Server"
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
https://www.geeksforgeeks.org/sql-delete-statement/?ref=lbp
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
'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
https://docs.microsoft.com/en-us/sql/t-sql/statements/truncate-table-transact-sql?view=sql-server-ver15
Delete from <tablename>
This will delete entire rows unless restricts through a where clause.