Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Add Constraint

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2009-08-04 : 12:51:18
Hello,

Can't I add two constraints in one single Alter Table command?

alter table dbo.PostsTags
add constraint FK_PostsTags_Posts foreign key (PostId) references Posts (Id) on delete cascade on update no action
constraint FK_PostsTags_Tags foreign key (TagId) references Tags (Id) on delete cascade on update no action;


I get the error:
Incorrect syntax near the keyword 'constraint'.

Thank You,
Miguel

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-08-04 : 13:08:39
Need to separate the CONSTRAINTs via a comma.
quote:
Originally posted by shapper

Hello,

Can't I add two constraints in one single Alter Table command?

alter table dbo.PostsTags
add constraint FK_PostsTags_Posts foreign key (PostId) references Posts (Id) on delete cascade on update no action
,constraint FK_PostsTags_Tags foreign key (TagId) references Tags (Id) on delete cascade on update no action;


I get the error:
Incorrect syntax near the keyword 'constraint'.

Thank You,
Miguel

Go to Top of Page
   

- Advertisement -