Mat*_*iby 2 mysql database database-design primary-key
我有这个数据库结构
CREATE TABLE `productinfo` (
`ProductID` int(11) NOT NULL AUTO_INCREMENT,
`ProductName` varchar(255) NOT NULL,
`ProductImage` varchar(255) NOT NULL,
`CategoryID` int(11) NOT NULL,
`SubCategoryID` int(11) NOT NULL,
`ProductBrief` varchar(255) NOT NULL,
`Features` text NOT NULL,
`Specifications` text NOT NULL,
`Reviews` text NOT NULL,
`Price` varchar(255) NOT NULL,
`Status` tinyint(4) NOT NULL,
PRIMARY KEY (`ProductID`)
) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=latin1;
Run Code Online (Sandbox Code Playgroud)
我现在需要将ProductID,CategoryID和SubCategoryID转换为Ps-5678这样的字符串作为部件号.ProductID是主键,因此如何更改数据库的结构.CategoryID和SubCategoryID是其他表中的主键,因此我如何处理它......就像转动一样容易
`ProductID` int(11) NOT NULL AUTO_INCREMENT
Run Code Online (Sandbox Code Playgroud)
变成一个字符串......并摆脱它
PRIMARY KEY (`ProductID`)
Run Code Online (Sandbox Code Playgroud)
想法,建议任何人
主键用于数据库.
显示名称适用于最终用户.
不要混淆彼此!不要用有意义的东西制作主键.你迟早会后悔的.
将代理键/身份/自动编号作为主键是一个非常好的主意,并且在数据库设计中被广泛使用.
您可以添加列甚至是DERIVED COLUMN,并在其上添加唯一约束.