MySQL Forums
Forum List  »  Microsoft SQL Server

usage of if exists()
Posted by: Samir Seba
Date: March 29, 2006 10:22AM

Hello,

i have the following script in MSSQL :

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Test]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
begin
ALTER TABLE [dbo].[Test] DROP CONSTRAINT FK_Test
end
GO

I did the following code in MySQL :

if exists (SELECT constraint_name FROM
information_schema.TABLE_CONSTRAINTS where
constraint_name='FK_Test')
then
ALTER TABLE Test DROP FOREIGN KEY FK_Test;
end if;
\g

and i got the error :

1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the r
syntax to use near 'if exists ( SELECT constraint_name FROM
information_schema' at line 1

i did the same syntaxe but inside a stored procedure and it's workign fine.


any Comments ?
Thank's




ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the r
ight syntax to use near 'if exists ( SELECT constraint_name FROM
information_schema' at line 1

Options: ReplyQuote


Subject
Written By
Posted
usage of if exists()
March 29, 2006 10:22AM
March 29, 2006 04:24PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.