gpt4 book ai didi

mysql - 优化的数据类型+简单的数据库设计

转载 作者:太空宇宙 更新时间:2023-11-03 10:28:05 25 4
gpt4 key购买 nike

我正在使用一个简单的数据库设计,我认为最好的数据库示例是电子商务,因为它确实有很多问题,而且它对 cms 很熟悉。

USERS TABLE
UID |int | PK NN UN AI
username |varchar(45) | UQ INDEX
password |varchar(100) | 100 varchar for $6$rounds=5000$ crypt php sha512
name |varchar(100) | 45 for first name 45 for last 10 for spaces
gender |bit | UN ,0 for women 1 for men, lol.
phone |varchar(30) | see [2]
email |varchar(255) | see RFC 5322 [1]
verified |tinyint | UN INDEX
timezone |tinyint | -128 to 127 just engough for +7 -7 or -11 +11 UTC
timeregister |int | 31052010112030 for 31-05-2010 11:20:30
timeactive |int | 01062010110020 for 1-06-2010 11:00:20

COMPANY TABLE
CID |int | PK NN UN AI
name |varchar(45) |
address |varchar(100) | not quite sure about 100.
email |varchar(255) | see users.email, this is for the offcial email
phone |varchar(30) | see users.phone
link |varchar(255) | for www.website.com/companylink 255 is good.
imagelogo |varchar(255) | for the retrieving image logo & storing
imagelogosmall |varchar(255) | not quite good nameing huh? let see the comments
yahoo |varchar(100) | dont know
linkin |varchar(100) | dont know
twitter |varchar(100) | twitter have 100 max username? is that true?
description |TEXT | or varchar[30000] for company descriptions
shoutout |varchar(140) | status that companies can have.
verified |tinyint | UN INDEX

PRODUCT TABLE
PID |int | PK NN UN AI
CID |int | from who?santa? FK: company.cid cascade delete
name |varchar(100) | longest productname maybe hahaha.
description |TEXT | still confused useing varchar[30000]
imagelarge |varchar(255) | for the retrieving product image & storing
imagesmall |varchar(255) | for the retrieving small product image & storing
tag |varchar(45) | for tagging like stackoverflow ( index )
price |decimal(11,2) | thats in Zimbabwe dollar.
  1. 参见 Using a regular expression to validate an email address
  2. 参见 What's the longest possible worldwide phone number I should consider in SQL varchar(length) for phone

为什么特定于 innodb?请参阅报价How to choose optimized datatypes for columns [innodb specific]?

它进入主题,所以我不得不提出另一个问题,但人们不明白我想说什么,或者我无法解释我想表达的意思。这次是 + 数据库设计。

所以再次请 复制上面的示例并像示例一样放置您的更改和评论 。给个建议。

记得用INNODB mysql。阅读上面链接中的引述。谢谢。

最佳答案

我会像您征求有关列定义的建议一样回答这个问题。我不会复制和粘贴您的表格,因为那完全是愚蠢的。

  • 不要将日期和时间存储为整数。请改用 DATETIME 列。
  • 请记住,MySQL 将 DATETIME 存储为 GMT,但会以配置使用的任何时区显示它们。可能值得setting the connection time zone到格林威治标准时间,以便您的单独时区存储能够正常工作。
  • 请记住,并非所有时区都与格林威治标准时间相差整整一小时。夏令时也可以在基于小时的计算中投入事件 Spanner 。您可能想要存储时区字符串(即“America/Los_Angeles”)并在运行时计算出正确的偏移量。
  • 您不需要为整数列指定字符数。
  • 不要害怕 TEXT 列。对于长度很容易超过 255 个字符的数据,例如 URL,您有很多 VARCHAR(255)。

请记住,优化特定数据库引擎或优化磁盘存储是您最不应该做的事情。使您的列定义适合数据。过早的优化是这个世界上万恶之源之一。不要担心 tinyint vs smallint vs int vs bigint,或者 char vs varchar vs text vs bigtext。只要数据适合,95% 的时间对您来说都无关紧要。

关于mysql - 优化的数据类型+简单的数据库设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3292710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com