开发者

mysql setting a negative integer value to a primary auto increment field which is int

开发者 https://www.devze.com 2023-01-12 16:02 出处:网络
I have a table which maintains categories from another site. I populate this table with the data i fetch from other site as xml.

I have a table which maintains categories from another site.

I populate this table with the data i fetch from other site as xml.

The data are divided as categories and products.

Some products does not have a category and the category xml does not have the others category.

So what i thought was to add a category others and setting its primary auto increment ID field to -1. So while inserting values into products ta开发者_Go百科ble for all the entries which dosent have a category i am setting to -1.

The auto increment initial values is 1.

Is this a good practice. will it be valid or will it be a problem sometimes later for some conditions(any)?

The db operations are working well but i want to know if it could be a problem later.


option one (my preference) - allow in products table categoryid == NULL. This is clearly shown non-categorized products.

option two - create default category and assign product to this category if product category not specified

0

精彩评论

暂无评论...
验证码 换一张
取 消