#1064 - You have an error in your SQL syntax; chec

2019-07-27 10:52发布

I am using Sybase Power Designer to create a database from a physical data model (Sybase creates an SQL file) . When i import the SQL file with phpMyAdmin I have the following error:

#1064 - 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 'if exists(select 1 from sys.sysforeignkey where role='FK_ARTWORK_CREATES_ARTIST'' at line 7 .

Any ideas? Could this error appear due to errors on the physical model or there is another problem?

This is the code :

if exists(select 1 from sys.sysforeignkey where role='FK_ARTWORK_HAS_BUY') then
    alter table artwork
       delete foreign key FK_ARTWORK_HAS_BUY
end if;

2条回答
The star\"
2楼-- · 2019-07-27 11:35

The error you are getting is from MySQL. Regardless of the tool used to generate SQL, the database seems to be MySQL (or something is terribly wrong with your systems if they are confused and think they are MySQL).

The MySQL if statement (documented here) has to be inside a stored program. That means that this code only compiles inside a stored procedure, user defined function, or trigger. It doesn't "just work" on its own.

In addition, MySQL doesn't have sys tables. It uses information_schema tables. My strongest suggestion is to use tools appropriate for your actual database. If you are using a tool to generate Sybase, then use Sybase as the destination database. If you are using MySQL, then use a tool to generate MySQL code. Or, better yet, learn how to write the commands yourself.

Finally, if you intend to use Sybase, then connect to the correct database and your problem should be fixed.

查看更多
放荡不羁爱自由
3楼-- · 2019-07-27 11:40

As I can't post here, and sqlfiddle.com temporary unavailable, I decided to post code with correct syntax for Sybase on the PasteBin

查看更多
登录 后发表回答