组合具有相同名称的两列数据以创建视图

时间:2021-10-22 20:21:11

I am working on a project and for my login credentials checking process I am trying to create a view in which the name,surname,username and password of customers,workers and admins are stored so that I can search faster and I have two questions.

我正在研究一个项目和我的登录凭据检查过程我正在尝试创建一个视图,其中存储了客户,工作人员和管理员的姓名,用户名和密码,以便我可以更快地搜索,我有两个问题。

  1. Do you think it is a good idea to do that ?
  2. 你认为这样做是个好主意吗?

  3. If yes, can you help me how to do that?
  4. 如果是的话,你能帮我怎么做吗?

Thank you in advance.

先感谢您。

2 个解决方案

#1


1) yes, but for simplicity rather than performance (and a few other reasons)

1)是的,但为了简单而不是表现(以及其他一些原因)

2) CREATE OR REPLACE VIEW viewname AS your_select_statement;

2)创建或替换视图viewname为your_select_statement;

#2


If the front-end is a single interface for both customers and employees then the tables should not be separated in the first place. If you have a person who is both a customer and a worker then they would appear on two tables and it is possible the data would not be synchronized between the two and if you create a view then they would appear twice. Instead create a single table for all people and have separate tables for data specific to customers, workers and admins.

如果前端是客户和员工的单一界面,则表格不应该首先分开。如果您有一个既是客户又是工人的人,那么他们会出现在两个表中,并且数据可能不会在两者之间同步,如果您创建一个视图,那么它们将出现两次。而是为所有人创建一个表,并为特定于客户,工作人员和管理员的数据提供单独的表。

Something like:

People

id | firstname | surname | username | password_hash | password_salt
--------------------------------------------------------------------
1  | alice     | abbot   | aa       | abc           | 123
2  | bob       | barnes  | bb       | def           | 456
3  | charlotte | carol   | cc       | ghi           | 789
4  | daniel    | david   | dd       | jkl           | 036

Customers

id | Credit_Limit | has_Trade_Account
-------------------------------------
2  | 0            | 0
3  | 2000         | 1

Workers

id | Joining_Date | Grade 
--------------------------
1  | 2015-01-01   | 5
3  | 2000-12-25   | 3

Admins

id | Edit_Permissions 
----------------------
3  | Orders
3  | Stock

#1


1) yes, but for simplicity rather than performance (and a few other reasons)

1)是的,但为了简单而不是表现(以及其他一些原因)

2) CREATE OR REPLACE VIEW viewname AS your_select_statement;

2)创建或替换视图viewname为your_select_statement;

#2


If the front-end is a single interface for both customers and employees then the tables should not be separated in the first place. If you have a person who is both a customer and a worker then they would appear on two tables and it is possible the data would not be synchronized between the two and if you create a view then they would appear twice. Instead create a single table for all people and have separate tables for data specific to customers, workers and admins.

如果前端是客户和员工的单一界面,则表格不应该首先分开。如果您有一个既是客户又是工人的人,那么他们会出现在两个表中,并且数据可能不会在两者之间同步,如果您创建一个视图,那么它们将出现两次。而是为所有人创建一个表,并为特定于客户,工作人员和管理员的数据提供单独的表。

Something like:

People

id | firstname | surname | username | password_hash | password_salt
--------------------------------------------------------------------
1  | alice     | abbot   | aa       | abc           | 123
2  | bob       | barnes  | bb       | def           | 456
3  | charlotte | carol   | cc       | ghi           | 789
4  | daniel    | david   | dd       | jkl           | 036

Customers

id | Credit_Limit | has_Trade_Account
-------------------------------------
2  | 0            | 0
3  | 2000         | 1

Workers

id | Joining_Date | Grade 
--------------------------
1  | 2015-01-01   | 5
3  | 2000-12-25   | 3

Admins

id | Edit_Permissions 
----------------------
3  | Orders
3  | Stock