i have two postgreSQL tables linked by a foreign key. I want to insert into the second table the data coming from the first table primary key. I wrote that in my c# application :
command1.CommandText = "CREATE TABLE table1(ID CHAR(256) CONSTRAINT id PRIMARY KEY, Title CHAR)";
command1.ExecuteNonQuery();
command1.CommandText = "insert into projects (ID, Title)" + "values(@id, @title);";
command1.Parameters.AddWithValue("@id", ID);
command1.Parameters.AddWithValue("@title",Title);
command1.ExecuteNonQuery();
For the second table:
command2.CommandText = "CREATE TABLE table2(table1id CHAR(256), champs1 CHAR(256), foreign key (table1id) references table1(ID))";
command2.ExecuteNonQuery();
The problem is that i dont know how to insert in table 2 the first column which is the primary key of the first table.
Any thoughts about that ? Thank you for your help :)