P
P
Pavel2019-10-31 02:53:28
SQL
Pavel, 2019-10-31 02:53:28

How to enter data into two tables?

There are two tables connected by the field Passport number. Both cannot be null. It is necessary for me when I write in the first table the data in this column, it was transferred at once there. But I'm getting an error. Maybe there is a way. I try through the trigger. But it is when the addition occurs, but it does not occur.

create trigger aaa  on Писатели after
 insert 
as
begin
insert into Контракты([Номер паспорта]) select Писатели.[Номер паспорта] from Писатели
insert into Книги([Номер контракта]) select Контракты.[Номер паспорта] from Контракты
end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
inFureal, 2019-10-31
@inFureal

Here, most likely, the type of relationship "One to many"
is needed. There is a table Pasports, where fields for example (id, number, ...)
Then you add this passport id to other tables. This way of storing data will bring fewer errors, there is no duplication and it is easier to understand the architecture of the database.
Here is a well written about this type of
stackoverflow links

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question