如何使用3个表的相同列创建单个表. [英] How to create a single table using same columns of 3 tables.

查看:89
本文介绍了如何使用3个表的相同列创建单个表.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个表Admin,Customer和Designer.
每个表都有名为Email n password的逗号列.

我想使用这两列创建一个表.
这样我就可以在一个表中拥有Admin管理员,Customer n Designer的Email n密码.

我该怎么办?
请告诉我.

I have 3 tables of Admin, Customer and designer.
Each table has comman columns named Email n password

I want to create a single table using these 2 columns.
So that i can have Email n password of Admin, Customer n Designer in a single table.

how can i do it??
Plz tell me.

推荐答案

这有点复杂,我无法真正具体回答.
原因是它取决于许多因素:
如果您创建一个包含电子邮件和密码信息的信息表,则有两种方法可以将其与原始表相关联:1)您可以在Admin表中拥有一个InfoId字段,在Customer表中拥有一个InfoId,并且Designer表中的InfoId,每个ID都引用Info表中的一行,并且如有必要,它们都可以引用同一行.因此,如果您通过Admin表对InfoId的引用来更改密码,它将自动为Customer和Designer更改密码.
2)您可以在Info表中有一个UserID字段,该字段返回到相应的Admin,Customer或Designer表.为此,您要么需要在整个系统中唯一的ID(以便您可以分辨出它来自哪个表),要么需要Info表中的附加字段这是一个管理员ID".

我?我可能会选择第一个-但是这将取决于您的系统应该如何工作.


顺便说一句:您不是希望这些密码以明文形式存储吗?您正在对它们进行哈希处理,对吧?
This is a little complex, and I can''t really answer it specifically.
The reason is that it depends on a number of factors:
If you create an Info table which holds the email and password info there are two ways you can relate it back to the original table: 1) You can have an InfoId field in the Admin table, and an InfoId in the Customer table, and an InfoId in the Designer table, each of which refer to a row in the Info table, and which could all refer to the same row if necessary. So if you change the password for via the Admin table reference to the InfoId, it will automatically change it for the Customer and Designer.
2) You can have a UserID field in the Info table which refers back to the appropriate Admin, Customer or Designer table. For this to work, you either need ids which are unique across the system (so you can tell which table it came from) or an additional field in the Info table which says "this is an admin id".

Me? I''d probably go with the first one - but it will depend on how your system is supposed to work.


BTW: You aren''t storing those passwords in clear text, I hope? You are hashing them, right?


假设所有这些表中的电子邮件和密码数据都相同,则可以使用以下SQL创建新表:
Assuming data is same in all these tables for email and password, you can create new table by using the following SQL:
SELECT email, password INTO new_table_name from existing_table 

,请查看以下链接以获取示例&更多详细信息:
http://www.w3schools.com/sql/sql_select_into.asp [

Check the following link for examples & more details:
http://www.w3schools.com/sql/sql_select_into.asp[^]



解决方案是创建一个包含4列的表:Id,Email,Password,PersonId,然后您需要在3个表和新表之间创建一个关系.我的意思是3个表的ID必须是新表的外键:
新表具有四个字段:

ID-新表的主键
密码
电子邮件
PersonId-这是来自3个表的外键


希望对您有所帮助,
干杯
Hi,
The solution is to create a table which has 4 columns: Id, Email, Password, PersonId and then you need to create a relation between 3 tables and the new table. I mean id of the 3 tables must be a foreign key of the new table:
New table has four fields:

Id --Primary key of the new table
Password
Email
PersonId -- which is a foreign key from the 3 tables


I hope it will help,
Cheers


这篇关于如何使用3个表的相同列创建单个表.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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