如何使用sp创建序列并将数据插入数据库 [英] How to create sequence and insert data into database using sp

查看:99
本文介绍了如何使用sp创建序列并将数据插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c#代码中有一个表,其中有3列第一行列数据将插入数据库并且它将生成一个id并基于该id第二行数据将插入并基于生成的id由第二列第3行数据将插入数据库





值可以重复



喜欢



喜欢3桌我ihave

kra目标标准





kra1 goal1 criteria1

kra1 goal1 criteria2

kra2 goal2 criteria3

kra2 goal3 criteria4

like这个



kra目标和标准可以重复

一个kra可以包含多个目标,一个目标可以包含多个标准



我尝试了什么:



i无法在sp中执行,而在c#中尝试它在不同的sceneria中失败,而且在c#中做的也是不对的我觉得

i have a table in c# code which has 3 column fist first row column data will insert in database and it will generate a id and based on that id 2nd row data will insert and based on generated id by 2nd column 3rd row data will insert into database


value can be repated

like

like 3 table i ihave
kra goal criteria


kra1 goal1 criteria1
kra1 goal1 criteria2
kra2 goal2 criteria3
kra2 goal3 criteria4
like this

kra goal and criteria can be repeated
one kra can contail multiple goal and one goal can contain multiple criteria

What I have tried:

i am unable to do in sp ,while trying in c# it failing in different sceneria and that is not right to do in c# also what i feel

推荐答案

不要。

相反,将其组织为三个表:

kra是一个表:ID是IDENTITY字段。

目标是第二个表:它也是有一个IDENTITY ID字段,以及kra表中ID的外键。

Criteria是第三个:再次,IDENTITY ID字段,以及Goals表中ID的外键。

然后当你想要检索数据时,你使用JOIN来建立你的SELECT。

这样,你就不会不必要地复制信息了。

在你的SP中执行INSERT是微不足道的。
Don't.
Instead, organise it as three tables:
kra is one table: the ID is an IDENTITY field.
Goals is a second table: it too has an IDENTITY ID field, and a foreign key to the ID in the kra table.
Criteria is the third: again, and IDENTITY ID field, and a foreign key to the ID in the Goals table.
Then when you want to retrieve the data, you use JOINs to build up your SELECT.
That way, you don't duplicate information unnecessarily.
It's then trivial to do the INSERTs in your SP.


这篇关于如何使用sp创建序列并将数据插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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