Files
SMT-ERP/smtERP-boot/docs/create_customer_tables.sql
2026-10-13 16:15:00 +08:00

46 lines
2.4 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 客户分类表
CREATE TABLE IF NOT EXISTS `tbl_customer_category` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`category_name` varchar(100) DEFAULT NULL COMMENT '分类名称',
`parent_id` bigint(20) DEFAULT 0 COMMENT '父分类ID,0表示顶级',
`level` int(11) DEFAULT 1 COMMENT '层级',
`sort` varchar(20) DEFAULT NULL COMMENT '排序',
`description` varchar(500) DEFAULT NULL COMMENT '描述',
`enabled` tinyint(1) DEFAULT 1 COMMENT '是否启用',
`creator` bigint(20) DEFAULT NULL COMMENT '创建人',
`tenant_id` bigint(20) DEFAULT NULL COMMENT '租户ID',
`delete_flag` varchar(1) DEFAULT '0' COMMENT '删除标记',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_parent_id` (`parent_id`),
KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='客户分类表';
-- 客户联系人表
CREATE TABLE IF NOT EXISTS `tbl_customer_contact` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`customer_id` bigint(20) NOT NULL COMMENT '客户ID',
`contact_name` varchar(50) DEFAULT NULL COMMENT '联系人姓名',
`position` varchar(50) DEFAULT NULL COMMENT '岗位(采购、财务等)',
`phone` varchar(30) DEFAULT NULL COMMENT '手机号',
`telephone` varchar(30) DEFAULT NULL COMMENT '座机',
`email` varchar(100) DEFAULT NULL COMMENT '邮箱',
`wechat` varchar(50) DEFAULT NULL COMMENT '微信',
`qq` varchar(30) DEFAULT NULL COMMENT 'QQ',
`is_primary` tinyint(1) DEFAULT 0 COMMENT '是否主要联系人',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`creator` bigint(20) DEFAULT NULL COMMENT '创建人',
`tenant_id` bigint(20) DEFAULT NULL COMMENT '租户ID',
`delete_flag` varchar(1) DEFAULT '0' COMMENT '删除标记',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_customer_id` (`customer_id`),
KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='客户联系人表';
-- 给 tbl_supplier 添加分类字段
ALTER TABLE `tbl_supplier` ADD COLUMN `category_id` bigint(20) DEFAULT NULL COMMENT '客户分类ID' AFTER `type`;
ALTER TABLE `tbl_supplier` ADD INDEX `idx_category_id` (`category_id`);