我有以下设置:
CREATE TABLE dbo.Licenses ( Id int IDENTITY(1,1) PRIMARY KEY,Name varchar(100),RUser nvarchar(128) DEFAULT USER_NAME() ) GO CREATE VIEW dbo.rLicenses AS SELECT Name FROM dbo.Licenses WHERE RUser = USER_NAME() GO
当我尝试使用视图插入数据…
INSERT INTO dbo.rLicenses VALUES ('test')
出现错误:
Cannot insert the value NULL into column Id,table master.dbo.Licenses; column does not allow nulls. INSERT fails.
情况是:
解决方法
命名列如何?
INSERT INTO dbo.rLicenses (name) VALUES ('test')
这是多年以来,我尝试通过视图更新,所以YMMV作为HLGEM提到.
我会考虑一个“INSTEAD OF” trigger的视图,允许一个简单的INSERT dbo.Licenses(即表)在触发器中