如何将两个SQL表信息绑定在一起 [英] How to bind two SQL tables info together

查看:101
本文介绍了如何将两个SQL表信息绑定在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理的网站是一个租车项目。

在我的主页上我有一个表格,用户可以选择接送日期,接送地点,退货日期,和汽车类型。

现在这4个信息是我在用户按下(预订)按钮时存储为cookie的输入值。

用户按下后(在主页中按下该按钮,表单将被提交,并在另一个页面中重定向,其中根据前一个表单的值向用户显示汽车列表。

点击汽车时你喜欢你去一个新的页面,你有汽车的详细信息,我也检索存储为cookie的表格的值,并显示它们,以防他想要更改它们。

所以在这个页面上有汽车详细信息,用户可以按下提交按钮预订汽车。



我尝试了什么:



现在在sql server中我有2个表(Products)和(RentInfo)。产品是我在管理面板中创建的产品,我也在页面中显示它们,(RentInfo)是我想在用户按下(预订)按钮后存储表单值和汽车详细信息的表格。汽车详细信息页面。

现在的问题是我如何在(RentInfo)表中保存表格值和汽车详细信息而不重复汽车细节,因为我已将它们放在(产品)中表。每次我想在管理面板中显示(RentInfo)表时,如何从那里检索它们?

我在VISUAL STUDIO ASP.NET中使用RAZOR WEB PAGES

如果它太难理解我的问题,请告诉我。

The site i am working on is a car rent project.
In my home page i have a form where the user can select Date of pick up , place of pick up , date of return , and the car type.
Now this 4 informations are input values that i store as cookies when the user presses the (book it) button.
After the user presses the (book it) button in the home page the form is submited and it redirects in another page where a list of cars is shown to the user according to the values of the previous form.
When click on a car you like you go to a new page where you have the car details and also i retrieve the values of the form that were stored as cookies and i display them in case he wants to change them.
So in this page with the car details the user can press the submit button to book the car.

What I have tried:

Now in the sql server i have 2 tables (Products) and (RentInfo). Products are the products that i create in the admin panel and i also display them in the pages and (RentInfo) is the table where i want to store the form values and the car details after the users presses the (book it) button in the car details page.
Now the problem is how can i save the form values and the car details in the the (RentInfo) table without duplicating the car details, since i have them already in the (Products) table. How can i retrieve them from there everytime i want to display the (RentInfo) table in my admin panel?
I WORK ON RAZOR WEB PAGES IN VISUAL STUDIO ASP.NET
If its too hard to understand my question please let me know.

推荐答案

从你提出问题的方式来看,你需要学习一些简单的数据库设计技巧。有很多免费资源可以帮助您 - 这是起点 [ ^ ]

基本上,每行都在您的Products表应该有一个唯一的标识符 - 这通常是 int identity(1,1),但很多人更喜欢GUID。无论哪种方式,重要的是每个行标识符在此表中是唯一的。

在RentInfo表中,您存储该标识符而不是所有汽车详细信息,并且在检索数据时您必须加入表例如
From the way you have phrased your question it sounds like you need to learn some simple database design techniques. There are plenty of free resources to help you - here is a starting point[^]
Basically, each row in your Products table should have a unique identifier - this is often an int identity(1,1) but many people prefer GUIDs. Either way, it is important that each row identifier is unique within this table.
On your RentInfo table you store that identifier instead of all of the car details, and when retrieving the data you must JOIN the tables e.g.
SELECT * 
FROM RentInfo 
INNER JOIN Products ON RentInfo.ProductID = Products.ProductID



以下是一些您可能会觉得有用的特定链接

使用汽车保险数据库样本进行关系数据库设计 [ ^ ]

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

SQL Server教程 [ ^ ]

MS SQL Server教程 [ ^ ]

或者如果您喜欢书籍,请尝试开始数据库设计 - 从新手到专业| Clare Churcher | Apress [ ^ ]

最后, http://www.databaseanswers.org/data_models/ 上有大量数据库设计示例[ ^ ]


Here are some specific links that you might find useful
Relational Database Design with an Auto Insurance Database Sample[^]
Visual Representation of SQL Joins[^]
SQL Server Tutorial[^]
MS SQL Server Tutorial[^]
Or if you prefer books try Beginning Database Design - From Novice to Professional | Clare Churcher | Apress[^]
Finally, there are loads of examples of Database design at http://www.databaseanswers.org/data_models/[^]


这篇关于如何将两个SQL表信息绑定在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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