Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to create foreign key in SQL?
Message
 
 
To
18/01/2002 08:25:55
General information
Forum:
Microsoft SQL Server
Category:
Database design
Miscellaneous
Thread ID:
00606630
Message ID:
00606713
Views:
30
What error do you get? Anyway, check/fix following:

- The column 'group_role' referenced in the PRIMARY KEY doesn't exist in the created table.
- Make sure that the 'groups' table exist and it has primary or candidate index on groups_id.
- Remove ';' semicolon from the CREATE TABLE statement.

>I failed to create foreign key in the following SQL statement.
>
>CREATE TABLE groups_role
>(
> groups_id varchar(5) NOT NULL,
> gr_role varchar(10) NOT NULL,
> gr_add bit DEFAULT(0) NOT NULL,
> gr_edit bit DEFAULT(0) NOT NULL,
> gr_delete bit DEFAULT(0) NOT NULL,
> gr_read bit DEFAULT(0) NOT NULL,
> PRIMARY KEY (groups_id, group_role),
> FOREIGN KEY (groups_id) REFERENCES groups(groups_id)
>);
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform