D
D
Drovosek012018-03-14 19:44:07
SQL Server
Drovosek01, 2018-03-14 19:44:07

How to set multiple foreign keys in one block of code?

I watch a training video: https://www.youtube.com/watch?v=Xux3_o2bImY
At 21 minutes of the video, 2 foreign keys are created from the Orders table to other tables

spoiler
5aa9500249a8b805046747.png

Question.
Would it be possible to create these 2 foreign keys in one block of code?
Like this or not...
ALTER TABLE Orders
ADD
FOREIGN KEY (CustomerID) REFERENCES Customers(ID)
FOREIGN KEY(EmployyID) REFERENCES Employees(ID)
GO

And if you need to create 100 foreign keys, why write 100 small blocks of code, isn't it easier to write everything in 1 block?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
d-stream, 2018-03-15
@d-stream

In real life, usually create with a huge pack and then at different points in time alter with quite visible to the eye creating a field + hanging a constraint.
Moreover, it is logically completely unprincipled where the error occurred there - it should not be (in an ideal world). Well, it goes without saying that "it turned out half" in the form of a field was created, but there is no restriction - this is also extreme - it's like a partial pregnancy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question