sqlite用触发器来替代外键约束
CREATE table [category] (
[PkID] INTEGER PRIMARY KEY autoINCREMENT NOT NulL,
[categoryname] NVARCHAR(32) NOT NulL,
[categoryGuID] char(36) UNIQUE NOT NulL,
[categoryDesc] nvarchar(256) NulL
)
CREATE table [Product] (
[PkID] INTEGER PRIMARY KEY autoINCREMENT NOT NulL,
[categoryPkID] INTEGER NOT NulL,
[Productname] nvarchar(32) NulL,
[ProductPrice] NUMERIC(19,4) DEFAulT '0.00' NOT NulL
)
--Insert约束
CREATE TRIGGER FK_Product_categoryPkID_Insert
BEFORE Insert ON Product
FOR EACH ROW BEGIN
SELECT RAISE(RolLBACK,'No this categoryPkID in category')
WHERE (SELECT PkID FROM category WHERE PkID = NEW.categoryPkID) IS NulL;
END
--Update约束 CREATE TRIGGER FK_Product_categoryPkID_Update BEFORE Update ON Product FOR EACH ROW BEGIN SELECT RAISE(RolLBACK,'No this categoryPkID in category') WHERE (SELECT PkID FROM category WHERE PkID = NEW.categoryPkID) IS NulL; END
总结以上是内存溢出为你收集整理的SQLite用触发器来替代外键约束全部内容,希望文章能够帮你解决SQLite用触发器来替代外键约束所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)