Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Constraints in SQL Server 2000
Message
De
14/03/2008 23:51:37
 
 
À
14/03/2008 23:47:59
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01302373
Message ID:
01302378
Vues:
7
You're welcome

>Beautiful - thanks!
>
>>Here is the basic syntax:
>>
>>ALTER TABLE DBO.< child table >
>>ADD CONSTRAINT < foreign key name > FOREIGN KEY < child column >
>>REFERENCES DBO.< parent table >( < parent column > )
>>{ON [DELETE|UPDATE] CASCADE}
>>
>>
>>>I think that's the answer, thanks! Contraints seem fairly straightforward.
>>>
>>>>You could use referential integrity and set it up as a foreign key. Will there ever be orphan queue records or will there always be a matching record in the Folders table? Is queue a child table? Are there any rules you want enforced between the two tables?
>>>>
>>>>Here is one example:
>>>>
>>>>ALTER TABLE DBO.QUEUE
>>>>ADD CONSTRAINT FK_QUEUE_FOLDER FOREIGN KEY (FOLDER)
>>>>REFERENCES DBO.FOLDERS(FOLDER)
>>>>ON DELETE CASCADE
>>>>
>>>>(not tested)
>>>>
>>>>In the above, a queue row cannot exist without an associated folders row. The ON DELETE CASCADE option tells the database engine that if the parent folders row’s folder is deleted, then any queue tied to the folders by the deleted folder should be automatically deleted as well.
>>>>
>>>>(Hope I typed that right = it is somewhat confusing because the table is named folder and the field is folder and the child table (?) is named queue and has a foreign key (?) field of folder if I understood you correctly)
>>>>
>>>>
>>>>>Hopefully a simple question, but I don't have much experience with writing contraints in SQL Server.
>>>>>
>>>>>I have one table called Folders with an ID field (autonumber PK) and a Folder field (varchar unique). This contains a list of folders.
>>>>>
>>>>>I have a second table called Queue. It has several fields, one of which being Folder (corresponds to the Folder field in the first table). How do I write a constraint to enforce that the contents of the Folder field in the Queue table exists in the Folder field in the Folders table?
>>>>>
>>>>>Thanks!
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform