我对 SQL 和 phpmyadmin 查询有疑问
I have question regarding SQL and phpmyadmin queries
我的数据库中有两个 table,第一个是 shop_details
,第二个是 shopOwner_login
在 shop_details
table 中有一个名为
的列
ShopOwner_email
Shop_Pass
与 shopOwner_login
table 中相同
ShopOwner_Id,
ShopOwner_email,
Shop_Pass
现在我想制作一个表格,如果用户在商店详细信息 table 中输入数据,例如店主电子邮件及其密码,它将自动存储在这两个 table 上
我可以这样做吗,如果可以,请帮助我。我也试过外键,我对外键很困惑,因为我是 php 和 MySql 的新手,请帮助我。
你的每个 table 都应该有主键。 主键是唯一的 id(可以是数字或字符串甚至 uuid。例如:ShopOwner_Id)可用于获取 table。此主键用于在 table 之间建立关系。
对于关系,两个 table 之间可能存在 3 种主要关系。
- 一对一
- 一对多或多对一
- 多对多
例如,
假设您有两个 tables UserLogin 和 UserProfile。 UserLogin 包含 -> id、email、password 和 verified。而 UserProfile 包含 -> id 名称、地址、手机、dob 等。这里每个 UserLogin 将有一个 UserProfile,而每个 UserProfile 将只有一个 UserLogin。所以他们有 一对一 关系。在这种情况下,您将外键添加到两个 table 中。您将在 UserLogin 中添加 profile_id 作为外键,而在 UserProfile 中添加 login_id。
比方说,您有两个 tables Shop
和 User
。其中每个 Shop
将属于一个 User
(在您的情况下是店主)但是一个 User
可以有多个 Shops
。在这种情况下,Shop
和 User
具有 多对一 关系( 或 User
和 Shop
具有 一对多关系)。在这种情况下,我们将 user_id 的外键( 是 User
table 的主键)添加到 Shop
table.
在你的情况下,我建议只将电子邮件和密码保存在 shopOwner_login
table 中,并将其外键添加到 shop_details
table。这样您的数据将被规范化,您将不必确保在多个 table 中维护相同的数据。
所以,d 查询需要获取数据,如下所示 - SELECT a.ShopOwner_email Shop_Pass as EmailId,a.Shop_Pass as Password FROM shop_details as a left join shopOwner_login as b on b.ShopOwner_Id = a.ShopOwner_Id
我的数据库中有两个 table,第一个是 shop_details
,第二个是 shopOwner_login
在 shop_details
table 中有一个名为
ShopOwner_email
Shop_Pass
与 shopOwner_login
table 中相同
ShopOwner_Id,
ShopOwner_email,
Shop_Pass
现在我想制作一个表格,如果用户在商店详细信息 table 中输入数据,例如店主电子邮件及其密码,它将自动存储在这两个 table 上
我可以这样做吗,如果可以,请帮助我。我也试过外键,我对外键很困惑,因为我是 php 和 MySql 的新手,请帮助我。
你的每个 table 都应该有主键。 主键是唯一的 id(可以是数字或字符串甚至 uuid。例如:ShopOwner_Id)可用于获取 table。此主键用于在 table 之间建立关系。
对于关系,两个 table 之间可能存在 3 种主要关系。
- 一对一
- 一对多或多对一
- 多对多
例如,
假设您有两个 tables UserLogin 和 UserProfile。 UserLogin 包含 -> id、email、password 和 verified。而 UserProfile 包含 -> id 名称、地址、手机、dob 等。这里每个 UserLogin 将有一个 UserProfile,而每个 UserProfile 将只有一个 UserLogin。所以他们有 一对一 关系。在这种情况下,您将外键添加到两个 table 中。您将在 UserLogin 中添加 profile_id 作为外键,而在 UserProfile 中添加 login_id。
比方说,您有两个 tables
Shop
和User
。其中每个Shop
将属于一个User
(在您的情况下是店主)但是一个User
可以有多个Shops
。在这种情况下,Shop
和User
具有 多对一 关系( 或User
和Shop
具有 一对多关系)。在这种情况下,我们将 user_id 的外键( 是User
table 的主键)添加到Shop
table.
在你的情况下,我建议只将电子邮件和密码保存在 shopOwner_login
table 中,并将其外键添加到 shop_details
table。这样您的数据将被规范化,您将不必确保在多个 table 中维护相同的数据。
所以,d 查询需要获取数据,如下所示 - SELECT a.ShopOwner_email Shop_Pass as EmailId,a.Shop_Pass as Password FROM shop_details as a left join shopOwner_login as b on b.ShopOwner_Id = a.ShopOwner_Id