Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DELETE*FROM table

Is there a way (similar to the below code) to delete all the rows in a specified table using c#?

SqlConnection con = new SqlConnection(conString);
con.Open();

string sql = @"DELETE*FROM compsTickers;";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
con.Close();

Right now i'm getting an error:

Incorrect syntax near '*'

like image 294
locoboy Avatar asked Mar 31 '11 07:03

locoboy


People also ask

Is delete * the same as drop table?

Delete statement removes only the rows in the table and it preserves the table structure as same, and Drop command removes all the data in the table and the table structure.

What does select * from table mean in SQL?

An asterisk (" * ") can be used to specify that the query should return all columns of the queried tables. SELECT is the most complex statement in SQL, with optional keywords and clauses that include: The FROM clause, which indicates the table(s) to retrieve data from.

What does delete from table in SQL?

The SQL DELETE Query is used to delete the existing records from a table. You can use the WHERE clause with a DELETE query to delete the selected rows, otherwise all the records would be deleted.


1 Answers

There's nothing wrong with your C# code; that's an SQL syntax error.

Anyway, there's no need for the *. You delete rows, not columns, from a table, so you don't specify columns to delete:

DELETE FROM compsTickers
like image 126
BoltClock Avatar answered Oct 11 '22 12:10

BoltClock