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
 General SQL Server Forums
 New to SQL Server Programming
 Insert query

Author  Topic 

Easwar
Yak Posting Veteran

59 Posts

Posted - 2007-03-23 : 02:24:00


I need three insert query into only one single query at a time .It's possible...

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-23 : 03:27:53
No.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-23 : 04:17:47
can you explain more in detail ?


KH

Go to Top of Page

Easwar
Yak Posting Veteran

59 Posts

Posted - 2007-03-23 : 04:41:33
This is my sample table Data

table1
TopicID|Topic
-------|--------
1|kkj
2|kjgg
3|jhkj
......
...

This is first insert (TopicID is primary Key)

table2
TagID|TagName
-----|--------
1|xyz
2|123abc
3|a3bc
....
...

this is second insert (TagId is primary key)

table3
DetID|TagID|TopicID
-----|-----|------------
1|1|1
2|1|2
3|1|3
4|2|4
....
...

this is 3rd insert (DetID is primary Key| TagID & TopicID is forgien key)

any query(single)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-23 : 04:46:22
Why single query ? What's wrong with 3 insert statement ?


KH

Go to Top of Page

Easwar
Yak Posting Veteran

59 Posts

Posted - 2007-03-23 : 04:53:45
when i first insert Topic into table1.... that time automatically insert the TopicID into table3. the same way when i insert TagName into table2.. That time automatically insert the TagId into table3.

It's possible.. any query(otherwise update query)
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-23 : 04:55:05
quote:
Originally posted by khtan

Why single query ? What's wrong with 3 insert statement ?


KH





Oh...come on, KH!!

Don't you know it takes 6 keystrokes just to copy and paste lines 3 times. Plus few more to make appropriate changes...my fingers hurts with that much coding...

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-23 : 05:00:40
quote:
Originally posted by Easwar

when i first insert Topic into table1.... that time automatically insert the TopicID into table3. the same way when i insert TagName into table2.. That time automatically insert the TagId into table3.

It's possible.. any query(otherwise update query)



"when i first insert Topic into table1.... that time automatically insert the TopicID into table3"
How to auto insert into table3 when you don't have the Tag_ID ?

Why not just create a stored procedure, pass in Topic, TagName and the stored procedure will insert into the 3 table ?

Is the TopicID, TagID an identity column ?


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-23 : 05:01:30
quote:
Originally posted by harsh_athalye

quote:
Originally posted by khtan

Why single query ? What's wrong with 3 insert statement ?


KH





Oh...come on, KH!!

Don't you know it takes 6 keystrokes just to copy and paste lines 3 times. Plus few more to make appropriate changes...my fingers hurts with that much coding...

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"





KH

Go to Top of Page

Easwar
Yak Posting Veteran

59 Posts

Posted - 2007-03-23 : 05:06:50
i don't know stored procedure.. plz tell me coding.. help me
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-23 : 05:07:42
Is the TopicID, TagID, DetID an identity column ?


KH

Go to Top of Page

Easwar
Yak Posting Veteran

59 Posts

Posted - 2007-03-23 : 05:09:06
yes
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-23 : 05:09:07
quote:
Originally posted by Easwar

i don't know stored procedure.. plz tell me coding.. help me


Writing stored procedure is very very easy. Give it a try. Take a look at this link http://www.sql-server-performance.com/tn_stored_procedures.asp


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-23 : 05:25:41
Post back if you have problem with the stored procedure. At least give it a try first.


KH

Go to Top of Page
   

- Advertisement -