|
|
Question : convert an SQL 2005 Script into SQL 2000 (foreignkey)
|
|
i got following SQL 2005 script which not runs under SQL Server 2000 :-(
---- script ------------------------------------- IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_users_users1]') AND parent_object_id = OBJECT_ID(N'[dbo].[machblog_user]')) ALTER TABLE [dbo].[machblog_user] WITH CHECK ADD CONSTRAINT [FK_users_users1] FOREIGN KEY([modified_by_id]) REFERENCES [dbo].[machblog_user] ([user_id]) GO ---- script -------------------------------------
--- errorMsg ---------------------------------- Server: Msg 208, Level 16, State 1, Line 1 Invalid object name 'sys.foreign_keys'. --- errorMsg ----------------------------------
I found that "sys.foreign_keys" sould be "sysforeignkeys", but that's not all of the Problem :-(
|
Answer : convert an SQL 2005 Script into SQL 2000 (foreignkey)
|
|
the sysforeignkeys has the following fields: constid fkeyid rkeyid fkey rkey keyno
so you have to use fkeyid instead of object_id and rkeyid instead of parent_object_id
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE fkeyid = OBJECT_ID(N'[dbo].[FK_users_users1]') AND rkeyid = OBJECT_ID(N'[dbo].[machblog_user]')) ALTER TABLE [dbo].[machblog_user] WITH CHECK ADD CONSTRAINT [FK_users_users1] FOREIGN KEY([modified_by_id]) REFERENCES [dbo].[machblog_user] ([user_id]) GO
|
|
|
|