0

I'm new to SQL Server and I wonder: I have built some tables that display the documents that produced in my program.

I need to write a stored procedure that inserts a document to the tables with transaction.

I think to create a main procedure with transaction that get 2 DTU of table: main and details

My question is: is it valid to create many DTU of table, for example: if in my DB their is 10 tables i need create 10 data type user of tables? How can I use polymorphism in the procedure parameter ,so I can write a one procedure that get for example: if i have 2 tables person and teachers that all teacher is person so my parameter will be alwase as person type but i allow send also teacher type ?

After I saw the XML type but its more slowly to use that and also it is more difficult

I wonder if SQL Server has other solutions to write to multiple tables with one transaction that would require fewer parameters?

Thanks for advance and hope that you will help me

T R
  • 1
  • 1
  • While asking a question, you need to provide a minimal reproducible example. Please refer to the following link: https://stackoverflow.com/help/minimal-reproducible-example Please provide the following: (1) DDL and sample data population, i.e. CREATE table(s) plus INSERT T-SQL statements. (2) What you need to do, i.e. logic, and your code attempt implementation of it. (3) Desired output based on the sample data in #1 above. (4) Your SQL Server version (SELECT @@version;) – Yitzhak Khabinsky Jun 18 '20 at 14:45

1 Answers1

0

It all depends on your front-end. If you have two different UI to capture header and details separately. You would need two separate stored procs, if not one stored proc would suffice. User Defined table type can decrease the number of params to stored proc. I agree XML is complex and user defined table type is much easier to use.

SMK
  • 11
  • 1
  • thank you on your answer! but i think i didnt explain myself well... i change my question and will be happy if you can answer me again – T R Jun 21 '20 at 12:15