如何插入以及将数据检索到具有主键 - 外键关系的表中 [英] how to insert as well as retrieve data into tables withprimary-foreign key relationship

查看:122
本文介绍了如何插入以及将数据检索到具有主键 - 外键关系的表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是编码的初学者,我使用三个名为tour package.tour描述,包含的表,这三个是通过主键和外键关系连接的。下面是我的表和它的表栏目



旅行套餐

id

标题

描述

image



旅游说明

id

地点

描述

image1



包含

id

包含



游览描述的id和包含的id是外键,他们指向游览包的id,这是主键。

任何人都可以告诉我如何使用c#和sql查询插入以及将数据检索到这三个表中。请帮助我。谢谢你提前。祝福你

Hi,
I am beginner in coding and i am using three tables named tour package.tour description,inclusion and these three are connected by primary and foreign key relationship.below is my tables and its columns

Tour Package
id
heading
description
image

tour description
id
place
description
image1

Inclusion
id
inclusion

tour description's id and inclusion's id are the foreign key and they point to tour package's id which is the primary key.
Can anyone tell me how to insert as well as retrieve data into these three tables using c# and sql query.please help me.Thank u in advance.god bless you

推荐答案

要进行检索,请使用SELECT和JOIN

1. sql_join [ ^ ]

2. SQL连接的可视化表示 [ ^ ]

用于插入,使用INSERT。但是,在将新数据插入具有相同新id的外表之前,必须确保新数据首先插入到具有新id的主表中。

3. sql_insert [ ^ ]

最后,你应该避免使用中间有空格的表名或字段名,这很烦人,因为你必须把它括起来,像这样:[旅游套餐]
For retrieval, use SELECT and JOIN
1. sql_join[^]
2. Visual Representation of SQL Joins[^]
For insertion, use INSERT. But you have to make sure that the new data is first inserted into the primary table with a new id, before it can be inserted into the foreign tables with the same new id.
3. sql_insert[^]
Lastly, you should avoid using table name or field name that has space in between, it is annoying, as you have to bracket it, like this: [Tour Package]


这篇关于如何插入以及将数据检索到具有主键 - 外键关系的表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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