开发者

How to update column in one table from another if both tables have a text field in common

I have two tables Token and distinctToken. Following is the description of the two tables.

Token (id int, text varchar(100), utokenid int)

distinctToken (id int, text varcha开发者_JS百科r(100))

The text field in both tables have same data with one exception, that is text field in Token table contains repeated entries.

I wanted to update the Token table such that the utokenid it becomes a foreign key. To be more specific i want to set the value of Token.utokenid = distinctToken.id where Token.text is the same as distinctToken.text. Is it possible using update or should i write a stored procedure to do so.


UPDATE Token t, distinctToken dt SET t.utokenid = dt.id WHERE t.text = dt.text;

Am I missing something?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜