将值插入主表后,如何在两个或多个表中插入相同的值. [英] How do I insert same values into two or more table after i insert values into primary table..

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

问题描述

我使用但无法获得理想结果的代码...
===
ParentTable
=====
创建表Parent
(
PID int约束Pidpk主键,
PName varchar(100),
)
====
ChildTable
=====
creat table Child
(
PID int约束Pidfk外键引用Parent(PID)
关于删除级联
在更新级联上,
CName varchar(100),
)
插入子值(PID,CName)
SELECT PID,PName
来自父母;
但是,当我在子表中插入更多值时,它将选择父表"中的所有数据",并一次又一次地插入重复数据...
请帮助我并将代码发送给我,该代码可以帮助我将完美的数据(而不是重复的数据)存储到子表中...

The code that i use but could not get the perfect result...
===
ParentTable
=====
creat table Parent
(
PID int constraint Pidpk primary key,
PName varchar (100),
)
====
ChildTable
=====
creat table Child
(
PID int constraint Pidfk Foreign key references Parent(PID)
on delete cascade
on update cascade,
CName varchar (100),
)
INSERT Child values(PID, CName)
SELECT PID, PName
FROM Parent;
But when I insert more values into child table it will select All Data from Parent table and insert duplicate data again and again...
Plz help me and send me the code which help me to store perfect data(not duplicate data) into child table ...

推荐答案

如果您不希望复制行,在所有列上执行Distinct,然后将其插入子表中.
If you dont want duplcate rows, do a Distinct on all columns and then insert them into the child table.


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

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