0

I have two table like this

table "X"

idX(pk) contentX(char)
10         foo1
21         foo2
34         foo3
45         foo4

table "Y"

idY(pk) contentY(char)
11         boo1
22         boo2
33         boo3
40         boo4

And after joining, intsert to a table and become this

idNew(pk)    idX(UQ) content(char)    idY(UQ) content(char)
   1           10         foo1           11         boo1
   2           21         foo2           22         boo2
   3           34         foo3           33         boo3
   4           45         foo4           40         boo4

The SQL I use is like this

    INSERT INTO DataBase.newtable(idX, contentX,idY,contentY)
        SELECT  X.idX, Y.idY, contentX, contentY
                FROM DataBase.X, DataBase.Y, ;

But the SQL statement cannot insert to newtable because the idX and idY is needed to be unique value. What can I do?

4

1 回答 1

0

您需要为该插入指定连接字段,否则您将获得两个表的笛卡尔积(即 16 行)。如果您在 idx 和 idy 字段上有唯一索引,则此约束将导致插入失败。

于 2012-11-03T06:54:23.880 回答