0

I have 3 tables, one of which uses 1 of the other 2's table's int PK as their FK. I'm not 100% familiar with SQL Server, but based on existing data and vis a where condition, is there a way to create insert statements for all 3 tables?

EDIT: One of these tables also has a blob, to make things (possibly) more complex.

LOL. NO.
  • 473
  • 1
  • 4
  • 23
  • Have you tried looking into http://stackoverflow.com/questions/16818796/generate-sql-insert-script-from-excel-worksheet – mhn May 09 '16 at 17:20
  • @mhn I haven't, but I forgot to mention that one of these tables also has a blob. Using the Excel method (assuming I just copy and paste data from a select query) would it still be possible? – LOL. NO. May 09 '16 at 17:22
  • Generating sql scripts is pretty straight forward in SQL Server. You can follow steps at http://stackoverflow.com/questions/5065357/how-to-generate-an-insert-script-for-an-existing-sql-server-table-that-includes or http://stackoverflow.com/questions/982568/what-is-the-best-way-to-auto-generate-insert-statements-for-a-sql-server-table – mhn May 09 '16 at 17:29

1 Answers1

0

Seems that you are looking for a trigger function, your INSERT statement will have the new.ID record and update the other two tables based on the ID of the first one.

Another option is that you use a stored procedure to insert the data in the 3 columns, where you set a variable for each info of the table and at the end to read the new.ID assigned in the tables and updates the 1st table.

We can help you a lot more if you tell us more details of your 3 tables, is it a customers table, products table etc.

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388