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.
| Author |
Topic |
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2010-04-06 : 06:32:57
|
| I want to enforce referential integrity between two tables.Each table has an Id (the key) which is an autonumber. However, my tables are linked by a text field. This is unique in the 'one' table. The other table contains the 'many' records. How can I do this?The database has been moved from Access to SQL, so I am stuck with the link being a text field. |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-04-06 : 06:37:51
|
| add a constraint (foreign key) on the child table on that column.There's no problem having your relationships as character columns (as long as they are still good candidates for a primary key).You haven't mentioned which column / set of columns in the table(s) are your keys. An ID column isn't necessary the key to a table.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2010-04-06 : 06:43:45
|
| add a constraint (foreign key) on the child table on that columnHow do I do that ? |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-04-06 : 06:50:32
|
| I'd advise you to read up on the:CREATE TABLEALTER TABLEcommands in books online.Here's a direct link to the CONSTRAINTShttp://msdn.microsoft.com/en-US/library/ms188066(v=SQL.90).aspxI see you've made about 500 posts. But I'm guessing they are mostly Access related?Which version of SQL SERVER are you using now. I've posted reference to 2005.Feel free to post the DML of the tables. You'll get some comment and advice.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2010-04-06 : 07:42:14
|
| Not Access on this site and not for about 8 years. I haven't used Access for about 8 years, but we have some old ones that need changing to sql and rewriting the apps in .netThanks for the links |
 |
|
|
|
|
|