最后一句話有問題(SQL Server 2019)。插入名為 MEMORIA USB 的產品后,出現下一個錯誤:
Msg 2628, Level 16, State 1, Procedure TR_ProductoInsertado, Line 4 [Batch Start Line 28]
String or binary data would be truncated in table 'inventario.dbo.historial', column 'usuario'. Truncated value: 'DESKTOP-NLVD399\unna'.
The statement has been terminated.
如果我洗掉觸發器并插入值,那么它作業正常
create table productos
(
id_Cod int identity primary key,
cod_prod varchar(4) not null,
nombre varchar(50)not null,
existencia int not null,
)
GO
Create table historial
(fecha date,
descripcion varchar(100),
usuario varchar(20))
GO
create table ventas
(cod_prod varchar(4),
precio money,
cantidad int
)
GO
create trigger TR_ProductoInsertado
on productos for insert
as
insert into historial values(getdate(), 'registro insertado', system_user)
go
insert into productos values('A001','MEMORIA USB 32GB',175);
有人能幫我嗎 ?
提前致謝
uj5u.com熱心網友回復:
你usuario有 20 個字符的空間,但你system_user的空間比這更長。
要么增加列的長度,要么system_user在插入之前截斷值。
create trigger TR_ProductoInsertado
on productos
for insert
as
insert into historial (fecha, descripcion, usuario)
values(getdate(), 'registro insertado', LEFT(system_user, 20));
uj5u.com熱心網友回復:
您的用戶名被截斷為“DESKTOP-NLVD399\unna”,超過了“inventario.dbo.historial”列“usuario”允許的 20 個字符
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/410816.html
標籤:
上一篇:SQL選擇另一個查詢的最有效方法
