mysql将负整数值设置为int的主自动增量字段 [英] mysql setting a negative integer value to a primary auto increment field which is int

查看:98
本文介绍了mysql将负整数值设置为int的主自动增量字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,用于维护另一个站点的类别.

I have a table which maintains categories from another site.

我用从其他站点获取的xml数据填充此表.

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

数据分为类别和产品.

The data are divided as categories and products.

某些产品没有类别,而类别xml没有其他类别.

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

所以我当时想添加其他类别并将其主要自动增量ID字段设置为-1.因此,在将所有我将其设置为类别的条目的值插入产品表时,将其设置为-1.

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 table for all the entries which dosent have a category i am setting to -1.

自动递增初始值为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.

推荐答案

选项一(我的偏爱)-在产品表中允许categoryid == NULL.清楚地显示了未分类的产品.

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

这篇关于mysql将负整数值设置为int的主自动增量字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆