PHP SQL 数据库
我有一个创建数据库,数据库中有大约 8 个表,还在相应的表中创建了主键和外键。但是当我在主表中插入数据时,我的其他表不显示更新的数据。
我的意思是,假设我有一个表,其中包含诸如以下名称的数据: N 是(名字) N1 = George,N2 = Ross,N3 = Rim ...等等,这意味着我有主键 N1,N2,N3 等。
现在,当我在其他表中插入这个主键时,它应该显示我的名字,例如 George,ross和 rim 而不是主键编号本身(N1,N2,N3)。
我怎样才能得到名字而不是PK本身?
I have a create database and have about 8 tables in Database also created Primary keys and foreign-keys in appropriate tables. But when I insert data in primary-table, my other table doesn't show updated data.
I mean, say I have a table which has data for names like ;
N is (name)
N1 = George, N2 = Ross, N3 = Rim ...etc now that means i have Primary key N1,N2,N3 etc..
Now, when I insert this primary keys in others table it should shows me name like George, ross and rim instead of primary-key number it self(N1,N2,N3).
How can I get names instead PK itself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您误解了关系数据库中键的概念。键的存在,不是为了从相似的表中复制数据,而是为了显示不同表中数据之间的关系。它们有助于理解不同表之间的数据如何相关——这就是“关系数据库”名称的由来。如果建立索引,它们还可以加快数据的查询速度。
您可以在此处阅读有关密钥用法的更多信息:密钥和规范化
You are misunderstanding the concept of keys in relational databases. Keys are there, not to copy data from similar tables but to show the relations between data in different tables. They help to understand how the data between different tables is related - that is where the name "relational database" comes from. They also speed up querying of that data if indexed.
You can read more about the usage of keys here: Keys and normalization
我仍然不清楚你到底想用数据库做什么。但让我向您演示数据库的基础知识以及应该如何使用它。考虑一个表
users
,您将在其中存储与用户相关的数据。列
id
保存主键并具有一个名为 auto_increment 的属性,现在这意味着每次您向该表插入一条记录时,id
属性都会递增,而您不需要不必担心在此列中插入任何值,因为您的数据库会处理这个问题。例如,看看下面的插入查询。您看到了吗,您没有在此处插入任何
id
。这是因为由数据库来处理逻辑。现在,第一条记录将保存值1
,第二条记录将保存2
,第三条记录将保存3
,第四条记录将保存4
>等等。希望这对你有帮助。
I am still unclear on what exactly you want to do with the database. but let me demonstrate you on the basic of database and how you should be using it. Consider a table
users
where you will be storing the data related to user.the column
id
holds the primary key and have an attribute called auto_increment, now what this means is every time you insert a record to this table theid
attribute gets incremented and you don't have to worry about inserting any value in this column because your database will take care of that. for example take a look at insert query below.did you see you did not insert any
id
here. this is because it is database who will handle the logic. now the first record will hold the value1
the second will have2
the third one3
and the fourth one4
and so on.hope this helps you.