在SQL Server中插入操作 [英] Insert operation in sql server

查看:89
本文介绍了在SQL Server中插入操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的成员,

帮我解决一个朋友问我的一个问题

有两个表table1和table2

表1有两列
colA-主键
colB--外键

表2有两列
colB--主键
colA--外键

Table1的colB取决于table2的colB
Table2的colA取决于table1的colA

将在这些表上执行插入操作

Dear Memebers,

Help Me out with the one question which one of my friend has asked me

There are two tables table1 and table2

Table1 has two columns
colA --primary key
colB-- foreign key

Table2 has two columns
colB--Primary key
colA--foreign key

Table1''s colB is dependent on table2''s colB
Table2''s colA is dependent on table1''s colA

Insert operation is to be performed on these tables

How can we perform this operation?

推荐答案

这是一个糟糕的设计,外键只能从子代到父代采用一种方式.
This is a bad design, foreign keys should only go one way from child to parent.


插入表_1(colA,colB)值(1,null)
插入表_2(colB,colA)值(1,1)
UPDATE table_1 SET colB = 1 WHERE colA = 1
INSERT INTO table_1(colA,colB) VALUES (1,null)
INSERT INTO table_2(colB,colA) VALUES (1,1)
UPDATE table_1 SET colB=1 WHERE colA=1


这篇关于在SQL Server中插入操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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