Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 multiple entry

Author  Topic 

bareyoungguy
Starting Member

7 Posts

Posted - 2006-01-15 : 08:54:05
iam new to MS SQL 7 server...i have two tables in my database say Table1 and Table2 having a comman field--- Name String(30). I want that dual data entry should be made for any single entry. That is if a name is entered in Table1, then same entry should be automatically entered in table2

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-15 : 09:00:33
Use stored procedure to do this. In your stored procedure,

insert into table1(col1, col2, ...)
select @col1, @col2

insert into table2(col1, col2, ...)
select @col1, @col2


-----------------
'KH'

Go to Top of Page

bareyoungguy
Starting Member

7 Posts

Posted - 2006-01-15 : 09:14:59
well this way you are actually writing two queries, i want to build a relation sort of thing with the two tables. So that only one query is needed.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-15 : 09:40:13
then create an insert trigger on Table1 that will auto insert into table2

-----------------
'KH'

Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-01-15 : 09:49:30
The above suggestion is better enough, but 2 more things can be suggested. (But may be not what u expect)

Suggestion 1: To have a trigger
Suggestion 2: To create the insert statement dynamically and use the same with corresponding table names.

Ur expected one may be logically represented as follows (It does not work, but if somebody knows to correct it it would be the one u r looking - I hope)
---------------- logic only -------------------
insert into table1 t1, table2 t2 (t1.col1, t1.col2, ...t2.col1, t2.col2....)
select @t1col1, @t1col2 ...... @t2col1, @t2col2
---------------- ^^^^^^^^^^^ -------------------

Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-01-15 : 13:54:29
quote:
Originally posted by bareyoungguy

well this way you are actually writing two queries, i want to build a relation sort of thing with the two tables. So that only one query is needed.



whats wrong with writing 2 sql statements ?

Its better than having an insert in a table and running a trigger. That way, you still have two queries
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-01-15 : 13:56:06
quote:
Originally posted by afrika

quote:
Originally posted by bareyoungguy

well this way you are actually writing two queries, i want to build a relation sort of thing with the two tables. So that only one query is needed.



whats wrong with writing 2 sql statements ?

Its better than having an insert in a table and running a trigger. That way, you still have two statements

Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-01-15 : 13:58:37
quote:
Originally posted by afrika

[quote]Originally posted by afrika

[quote]Originally posted by bareyoungguy

well this way you are actually writing two queries, i want to build a relation sort of thing with the two tables. So that only one query is needed.



whats wrong with writing 2 sql statements ?

Its better than having an insert in a table and running a trigger. That way, you still have two statements
Go to Top of Page
   

- Advertisement -