I have three tables [PublicationNotice], [PublicationNoticeClient] and [PublicationNoticeInvoice].
Table1 have one-to-one relation with table2 and table3.
I am using a stored procedure to insert data into the tables. My form consists of all attributes from table1, table2 and table3.
My problem is, when I Submit data into these three tables it inserts all data accept table2_id and table3_id in table1.
HINT: I am using ASP .Net and MSSQL
My stored procedure looks like this:
CREATE procedure [dbo].[AddUpdatePublicationNotice]
@ID bigint = NULL,
@Title varchar(max)= NULL,
@NewspaperName varchar(50) =NULL,
@Cities varchar(max)= NULL,
@PublicationSize varchar(8) =NULL,
@PublicationDate date =NULL,
@PublicationType varchar(50)= NULL,
@NewspaperPageNo smallint= NULL,
@Colored bit= NULL,
@CaseNature varchar(15)= NULL,
@ImagePath varchar(max)= NULL,
@ClientId bigint =NULL,
@InvoiceId bigint= NULL,
@CreatedById bigint = NULL,
@EditedById bigint= NULL,
@EditedDate datetime =NULL,
--******************************************--
@ClientName varchar(max)= NULL,
@ClientType varchar(50)= NULL,
@ClientContactPerson varchar(max)= NULL,
@ClientAddress varchar(max)= NULL,
@ClientCity varchar(50) =NULL,
@ClientCountry varchar(50)= NULL,
--******************************************--
@InvoiceDate date= NULL,
@InvoiceTotalAmount bigint= NULL,
@InvoicePaymentRecievedDate date= NULL,
@InvoiceChequeNo bigint= NULL,
@InvoiceBankName varchar(50)= NULL
--******************************************--
AS
Insert into PublicationNotice (
[Title]
,[NewspaperName]
,[Cities]
,[PublicationSize]
,[PublicationDate]
,[PublicationType]
,[NewspaperPageNo]
,[Colored]
,[CaseNature]
,[ImagePath]
,[ClientId]
,[InvoiceId]
,CreatedById
)Values(
@Title
,@NewspaperName
,@Cities
,@PublicationSize
,@PublicationDate
,@PublicationType
,@NewspaperPageNo
,@Colored
,@CaseNature
,@ImagePath
,@ClientId
,@InvoiceId
,@CreatedById)
insert into [dbo].[PublicationNoticeClient] (
[Name]
,[Type]
,[ContactPerson]
,[Address]
,[City]
,[Country]
,[CreatedById])
Values(@ClientName
,@ClientType
,@ClientContactPerson
,@ClientAddress
,@ClientCity
,@ClientCountry
,@CreatedById)
Insert Into [dbo].[PublicationNoticeInvoice] (
[Date]
,[TotalAmount]
,[PaymentRecievedDate]
,[ChequeNo]
,[BankName]
,[CreatedById])
Values (
@InvoiceDate
,@InvoiceTotalAmount
,@InvoicePaymentRecievedDate
,@InvoiceChequeNo
,@InvoiceBankName
,@CreatedById)
GO
I know I can first insert table2 and table3 values and then select the last inserted values from table2 and table3 (that are table2_id and table3_id) and then insert them into table1
Is there any other fast way to insert data like this ???