插入时如何使用外键

编程入门 行业动态 更新时间:2024-10-27 14:24:40
本文介绍了插入时如何使用外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有2个表艺术家和员工作为 艺术家(artistId,姓名,联系人,地址,employeeId)和 员工(employeeId,姓名,联系方式,电子邮件) 这里artistId和employeeId是主键并设置为自动增量。 我想将数据插入艺术家表格,但艺术家无法插入员工ID。那么它将如何分配给艺术家?我该怎么写? i在没有员工ID的存储过程中写了以下查询: 插入艺术家(姓名,联系方式,地址)值(姓名,联系方式,地址) 。 请帮忙。

i have 2 tables artist and employee as artist(artistId,name,contact,address,employeeId) and employee(employeeId,name,contact,email) here artistId and employeeId are primary key and set to auto increment. I want to insert data into artist table but artist can not insert employee Id.So how it will get assigned to artist? what should I write? i have written following query in stored procedure without employee id: insert into artist(name,contact,address)values(name,contact,address). Please help.

推荐答案

您必须先将新员工ID插入员工表中它可以在艺术家表中使用。 You have to insert new employee id into the employee table first before it can be used in the artist table.

查看 http: / techref:http://technet.microsoft/en-us/library _blanktitle =新窗口> ^ ] 但我建议不使用身份/自动增量。 SQL Server 2012支持各种更好的序列。 Look into technet.microsoft/en-us/library/ms190315.aspx[^] But I recommend not using an identity / auto increment. SQL Server 2012 supports sequences, which are all kinds of better.

更多推荐

插入时如何使用外键

本文发布于:2023-10-14 21:35:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492279.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:入时   如何使用

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!