Monday, March 12, 2012

Key column information is insufficient or incorrect. Too many...

Hi,

Im trying to Update a table called Contratos in the field Cliente from the table Clientes with the field Cliente.

Im using the follow Trigger :

CREATE TRIGGER UPDate_Clientes ON dbo.Clientes
FOR UPDATE
AS
update Contratos
set Cliente = inserted.Cliente
from Clientes
inner join inserted on Clientes.Cliente = inserted.Cliente

When I update the register the follow message in the application raise :

"Key column information is insufficient or incorrect. Too many rows were affected by update."

What is happen...Can somebody help me?

Leonardo AlmeidaOriginally posted by vectords
Hi,

Im trying to Update a table called Contratos in the field Cliente from the table Clientes with the field Cliente.

Im using the follow Trigger :

CREATE TRIGGER UPDate_Clientes ON dbo.Clientes
FOR UPDATE
AS
update Contratos
set Cliente = inserted.Cliente
from Clientes
inner join inserted on Clientes.Cliente = inserted.Cliente

When I update the register the follow message in the application raise :

"Key column information is insufficient or incorrect. Too many rows were affected by update."

What is happen...Can somebody help me?

Leonardo Almeida

Where is relation between Contratos and Clientes?|||This is the case... I would like to learn the statement that make the relation between these tables.
Why? Cos these are separated in two different databases and if a user make an update in a table from database X these changes must to be applied in the other table in the another database:

The tables are :

Principal Database Name : Server Information 2004
Table Name : Clients
Fields : ID_Client, Client

Secondary Database Name : Index2003
Table Name : Contratos
Fields : ID_Con, ID_Client, Client

I need to write a Trigger for Update the table Contratos everytime a user change the values in Clients.

Im using the follow Trigger :

CREATE TRIGGER UPDate_Clients ON dbo.Clients
FOR UPDATE
AS
update Contratos
set Client = inserted.Client
from Clients
inner join inserted on Clients.Client = inserted.Client

When I update the register the follow message in the application raise :

"Key column information is insufficient or incorrect. Too many rows were affected by update."

If somebody can help me THANKS A LOT OF...

Leonardo Almeida|||Try this one:

CREATE TRIGGER UPDate_Clients ON dbo.Clients
FOR UPDATE
AS
update Contratos
set Client = inserted.Client
from inserted on Contratos.ID_Client = inserted.ID_Client

--------
Only because of Pele|||Originally posted by vectords
This is the case... I would like to learn the statement that make the relation between these tables.
Why? Cos these are separated in two different databases and if a user make an update in a table from database X these changes must to be applied in the other table in the another database:

The tables are :

Principal Database Name : Server Information 2004
Table Name : Clients
Fields : ID_Client, Client

Secondary Database Name : Index2003
Table Name : Contratos
Fields : ID_Con, ID_Client, Client

I need to write a Trigger for Update the table Contratos everytime a user change the values in Clients.

Im using the follow Trigger :

CREATE TRIGGER UPDate_Clients ON dbo.Clients
FOR UPDATE
AS
update Contratos
set Client = inserted.Client
from Clients
inner join inserted on Clients.Client = inserted.Client

When I update the register the follow message in the application raise :

"Key column information is insufficient or incorrect. Too many rows were affected by update."

If somebody can help me THANKS A LOT OF...

Leonardo Almeida

Do every table have a primary key? If no - create primary keys...|||Yes ... each table has the primary key

ID_Client for Clients
ID_Con for Contratos|||This is working:

create table table1(id int primary key,uname varchar(10))
create table table2(id int primary key,id_2 int,uname varchar(10))
go
create trigger i_table1 on table1
for update
as
update table2
set uname=inserted.uname
from inserted where table2.id_2=inserted.id
go
insert table1 select 1,'test'
insert table2 select 1,1,'test'
go
update table1 set uname='test2' where id=1
select * from table1
select * from table2

Try to find error in your script.|||Thank you very much...
Can you send me your e-mail to leonardoalmeida2004@.yahoo.com.br to me give back a return from whats happen to my database I will put this struture you send me in my database and tables

THANK YOU VERY MUCH.

Leonardo Almeida

No comments:

Post a Comment