mysql8字段date_使用DATE字段作为MySQL的日期维度的主键

bd96500e110b49cbb3cd949968f18be7.png

I want to handle a date dimension in a MySQL datawarehouse. (I m a newbie in the DW world)

I made some searches with google and saw a lot of table structures (most of) date dimension where the Primary Key is a simple UNSIGNED INTEGER.

Why don't use a DATE field as primary key since with MySQL it is 3 Bytes VS 4 Bytes for INTEGER?

Ex:

CREATE TABLE dimDate

id INTEGER UNSIGNED NOT NULL PRIMARY AUTOI_NCREMENT,

date DATE NOT NULL,

dayOfWeek

...

VS

CREATE TABLE dimDate

date DATE NOT NULL PRIMARY,

dayOfWeek

...

解决方案

If you have a table with a column that is of date type and where no two rows will ever have the same date, then you can surely use this column as PRIMARY KEY.

You see a lot of examples where the Primary Key is a simple UNSIGNED INTEGER because there are many cases where there is no perfect candidate for Primary Key. The AUTO_INCREMENT allows this column to be automatically filled by the database (and be unique) during inserts .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值