skip to Main Content

I made a database for my project for ASP.NET in Visual Studio. Then I made a table however after updating the table, Visual Studio itself named it as ‘Table’. Now when I’m trying to run a query: select * from Table (.....) but it is throwing an error

Incorrect syntax near the keyword ‘Table’.

I even tried writing the table name as [Table] in the query but no effect.

Now what should I do?

Edit: I have found the solution myself after researching on this issue: If you are having similar issue then just rename the table and all should work fine:) Make sure to change this new table name in all the occurrences in your project.

2

Answers


  1. If you ever want to use a reserved word as an identifier in SQL then you need to escape it. That’s always the case and will be covered in any SQL tutorial. In SQL Server, you escape an identifier using brackets, e.g.

    SELECT * FROM [Table]
    

    Of course, you should change that table name immediately, then the issue goes away. That said, I tend to use singular names for my tables and I often end up with a User table. That’s a reserved word, so I have to escape it when I refer to it. No big deal.

    Login or Signup to reply.
  2. Check if your table name presents any schema or normal table.

    If the table is present in schema then try this query "Select * from [schema_name.Tablename];"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search