21 lines
1.0 KiB
SQL
21 lines
1.0 KiB
SQL
-- MySQL 8.0.16+;对Lastleg连接的实例完整执行,遇错停止。DDL隐式提交。
|
|||
|
|
USE `baiyue_lastleg`;
|
||
|
|
SET NAMES utf8mb4;
|
||
|
|
SELECT DATABASE() AS target_database, @@hostname AS mysql_host, @@port AS mysql_port;
|
||
|
|
|
||
|
|
-- 整箱废弃后保留SKU明细,剩余数量允许归零,仍禁止负库存。
|
||
|
|
-- 原子替换约束,可重复执行;不修改业务记录。
|
||
|
|
SET @ddl = IF(EXISTS (
|
||
|
|
SELECT 1 FROM information_schema.table_constraints
|
||
|
|
WHERE constraint_schema=DATABASE() AND table_name='ll_return_inventory_carton_item'
|
||
|
|
AND constraint_name='chk_ll_return_inventory_carton_item_quantity'
|
||
|
|
),
|
||
|
|
'ALTER TABLE ll_return_inventory_carton_item DROP CHECK chk_ll_return_inventory_carton_item_quantity, ADD CONSTRAINT chk_ll_return_inventory_carton_item_quantity CHECK(quantity>=0)',
|
||
|
|
'ALTER TABLE ll_return_inventory_carton_item ADD CONSTRAINT chk_ll_return_inventory_carton_item_quantity CHECK(quantity>=0)'
|
||
|
|
);
|
||
|
|
PREPARE stmt FROM @ddl;
|
||
|
|
EXECUTE stmt;
|
||
|
|
DEALLOCATE PREPARE stmt;
|
||
|
|
|
||
|
|
SHOW CREATE TABLE ll_return_inventory_carton_item;
|