如何将两个不同表中的recored插入到一个表中。 [英] how to insert recored from two diffirent table into one table.

查看:115
本文介绍了如何将两个不同表中的recored插入到一个表中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii,



i有3个表:= Contects(Coloum:ContentID(pk)标识,contenttext varchar)



句子(Coloumn:SentenceId(pk)身份,Sentencetext varcahr)



Contentsentence(Coloumn:ContentID int(pk),SentenceId int(pk), orderno int)



i想把内容表的contenid记录插入到Contentsentencetable和句子表的句子中的插入查询到Contentsentencetable并给出orderno那我该怎么办那个???)



(注意:ContentID和SentenceID是ContentSentence表的组合主键)



请提供我的SQL查询,以便我可以在我的代码中使用它。

Hii,

i have 3 tables:= Contects(Coloum:ContentID(pk) identity,contenttext varchar)

Sentence( Coloumn:SentenceId(pk) identity,Sentencetext varcahr)

Contentsentence(Coloumn: ContentID int (pk),SentenceId int (pk),orderno int)

i want to write insert query that insert record of contenid of content table into Contentsentencetable and sentenceid of sentence table into Contentsentencetable and also give orderno so how can i do that???)

(note:ContentID and SentenceID Are combined Primary key of the ContentSentence Table)

please provide me sql query so i can use it in my code.

推荐答案

如果第三个表也有自己的主键..我们可以使用此查询用于插入记录





插入c.contenttext,s.Sentencetext,cs.orderno

FROM Contects C,句子s,Contentsentence cs

其中c.Contects.ContentID = cs.Contentsentence

和cs.ContentsentenceID = s.SentenceId
if third table has also its own primary key..than we can use this query for inserting record


Insert into c.contenttext, s.Sentencetext,cs.orderno
FROM Contects c,Sentence s,Contentsentence cs
where c.Contects.ContentID =cs.Contentsentence
And cs.ContentsentenceID=s.SentenceId


您好,



在此查找单个查询以满足您的要求



Hi,

Find here single query for your requirement

INSERT INTO Contentsentence(ContentId, SentenceId)
SELECT ContentID,SenetenceId from 
Contects, Sentence
WHERE contenttext='Your Text'
AND Sentencetext='Your Text'
--Kindly note that these where conditions are not enough to select required data and insert it. You have to maintain some relationship between Contects, Sentence table.







检查你的要求和桌子结构正常。



希望这会对你有所帮助。



干杯




Check your requirement and table structure properly.

Hope this will help you.

Cheers


这篇关于如何将两个不同表中的recored插入到一个表中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆