0
IF OBJECT_ID(N`db_291702_2`.`aaCoRrankingDateManage`, N'U') IS NOT NULL
BEGIN
  PRINT 'Table Exists'
END

What is wrong with this? Why do I get errors? Neither of the suggested ways in how-to-check-if-a-table-exists-in-sql-server/ works for me.

PS. "does not work" means errors like

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''db_291702_2'.'aaCoRrankingDateManage' LIMIT 0, 30' at line 1

Additional info: I am using phpMyAdmin, my two databases are called db_291702_1 and db_291702_2, the latter has two tables, one of them is called aaCoRrankingDateManage

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
phil294
  • 10,038
  • 8
  • 65
  • 98

2 Answers2

0

If you want to escape table or column names then use backticks

select `group` from table1

A static string must be included in quotes

select * from users where name = 'john'

And the syntax of every DB engine is a little bit different. The above works for MySQL, but SQL-Server has a different syntax. There you use brackets [] to escape names.

But you only need to escape names if you use reserved words. You don't have to escape everything.

juergen d
  • 201,996
  • 37
  • 293
  • 362
-1

The given source code is no MySQL Code.

phil294
  • 10,038
  • 8
  • 65
  • 98