1: Your properties table should have a type_id foreign key column that references the type_id column from the types table. It should be an INT with the NOT NULL constraint
I used the query
alter table properties add column type_id int not null references types(type_id);
it shows me some error about null values, so I break the problem into mini problems as
add the column type_id to the table properties
insert the values manually one by one into each cell of type_id column (boring task)
add the constraint NOT NULL to column type_id
make it foreign key with reference from types(type)
Q: since the table has only few rows of data i completed the task in few minutes, and I don`t think it is a feasible solution.
what`s the correct way to do it?
Q : Is it possible to enter data into all three tables simultaneously using single query or I have to enter the data separately specific to that table?
Im sticking around since i have a similar doubt but for this question:
Your properties table should have a type_id foreign key column that references the type_id column from the types table. It should be an INT with the NOT NULL constraint
I wonder if there’s a way to make the reference to the other table and automatically fill in this values with the type_id of the types table.
About this part: it doesn’t need to be completed in one command. The way I resolved it was to add the column to the properties table, then fill it with data using UPDATE. Lastly, I added the NOT NULL constraint and the foreign key.
You can enter data into multiple columns with one command, but I don’t believe this is true for multiple tables.
Thanks for the reply, i know question does not need to be completed in one step and I indeed completed the way you said but I was wondering if there was a more optimal way to solve this question.