我正在为一家新公司开发应用程序管理业务(销售、供应商、客户、产品……)。首先,我需要创建一个数据库。您能否告诉我下面的 BD 方案是否良好和优化?
CREATE TABLE IF NOT EXISTS `company` (
id UNSIGNED INT NOT NULL auto_increment,
`SIRET` varchar(50) NOT NULL,
`nom` varchar(50) NOT NULL,
`description` varchar(500) NOT NULL,
`enable` ENUM('YES', 'NO') DEFAULT 'YES',
`level` int(1) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY SIRET (SIRET)
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
// contactType can be one of the 3 values : email, phone, fax
CREATE TABLE IF NOT EXISTS `contactType` (
id UNSIGNED INT NOT NULL auto_increment,
`contactType` ENUM('email', 'phonenumber', 'faxnumber')
`mobile` ENUM('YES', 'NO') default 'NO',
PRIMARY KEY (id),
UNIQUE KEY type (contactType)
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `contacts` (
id UNSIGNED INT NOT NULL auto_increment,
`SIRET` varchar(50) NOT NULL,
`contactType` varchar(50) NOT NULL, // A reference to contactType just above
`contactref` varchar(50) NOT NULL, // Phone number, fax number or email adress
PRIMARY KEY (id),
UNIQUE KEY type (SIRET)
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `customers` (
id UNSIGNED INT NOT NULL auto_increment,
`SIRET` varchar(50) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY type (SIRET)
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `supplier` (
id UNSIGNED INT NOT NULL auto_increment,
`SIRET` varchar(50) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY type (SIRET)
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `industry` (
id UNSIGNED INT NOT NULL auto_increment,
`industry` varchar(250) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY type (activite)
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `entreprisePerIndustry` (
id UNSIGNED INT NOT NULL auto_increment,
`industry_id` varchar(250) NOT NULL, // Chemical, Computer, Consulting, ...
FOREIGN KEY (industry_id) REFERENCES industry(id) ON DELETE CASCADE,
`SIRET` varchar(50) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY type (industry_id)
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;