OVH Cloud OVH Cloud

Colonnes modifiées par UPDATE

4 réponses
Avatar
patrick
Bonjour,

Existe-t-il un moyen de connaitre les champs d'une table qui ont été
modifiés par un UPDATE ?
Le but étant de "tracer" les modifications sur certaines colonnes d'une
table

Merci

4 réponses

Avatar
Med Bouchenafa
Dans un trigger, la caluse IF COLUMNS_UPDATED() permet de savoir les
colonnes modifiées
Voir Aide En ligne pour plus de détails

--
Bien cordialement
Med Bouchenafa

"patrick" wrote in message
news:uhgOTd%
Bonjour,

Existe-t-il un moyen de connaitre les champs d'une table qui ont été
modifiés par un UPDATE ?
Le but étant de "tracer" les modifications sur certaines colonnes d'une
table

Merci




Avatar
Rudi Bruchez
patrick a écrit:

Existe-t-il un moyen de connaitre les champs d'une table qui ont été
modifiés par un UPDATE ?
Le but étant de "tracer" les modifications sur certaines colonnes d'une
table



Bonjour,

A posteriori non. Tu peux faire un trigger pour tracer ces changements
quand ils se produisent.

--
Rudi Bruchez
Consultant indépendant
modélisation, administration, optimisation,
Solutions MS SQL Server et informatique libre.
MCDBA, SCJP2
http://www.babaluga.com/
Avatar
zoltix
patrick wrote:
Bonjour,

Existe-t-il un moyen de connaitre les champs d'une table qui ont été
modifiés par un UPDATE ?
Le but étant de "tracer" les modifications sur certaines colonnes d'une
table

Merci




dant ton trigger update ,
ca va te ramener toutes les rows qui ont été modifié.

Va voir chez MS tu vas comprendres pourquoi.

Doc de msql server 2005
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/765fde44-1f95-4015-80a4-45388f18a42c.htm


if ((select count(*)from deleted)>0 and (select count(*)from inserted)>0)
begin
--print 'update'
declare @i int
declare @b binary
set @position = 0
set @strChange =''
set @i = 1

--print columns_updated()
set @bit = columns_updated()
--print @bit

while(@i<=@iBinary)
begin



set @b = substring(@bit,@i,1)
--print 'binary'
--print @b

--print 'position'
--print @position

--print @position
if (@b & 1 ) =1 begin
--print 1+@position
select @strChange= @strChange +','+ltrim(rtrim(column_name)) FROM
INFORMATION_SCHEMA.COLUMNS where table_name =@table and
ordinal_position = 1+@position
end
if (@b & 2 ) =2 begin
--print 2+@position
select @strChange= @strChange +','+ltrim(rtrim(column_name)) FROM
INFORMATION_SCHEMA.COLUMNS where table_name =@table and
ordinal_position = 2+@position
end
if (@b & 4 ) =4 begin
--print 3+@position
select @strChange= @strChange +','+ltrim(rtrim(column_name)) FROM
INFORMATION_SCHEMA.COLUMNS where table_name =@table and
ordinal_position = 3+@position
end
if (@b & 8 ) =8 begin
--print 4+@position
select @strChange= @strChange +','+ltrim(rtrim(column_name)) FROM
INFORMATION_SCHEMA.COLUMNS where table_name =@table and
ordinal_position = 4+@position
end
if (@b & 16 )  begin
--print 5+@position
select @strChange= @strChange +','+ltrim(rtrim(column_name)) FROM
INFORMATION_SCHEMA.COLUMNS where table_name =@table and
ordinal_position = 5+@position
end
if (@b & 32 ) 2 begin
--print 6+@position
select @strChange= @strChange +','+ltrim(rtrim(column_name)) FROM
INFORMATION_SCHEMA.COLUMNS where table_name =@table and
ordinal_position = 6+@position
end
if (@b & 64 ) d begin
--print 7+@position
select @strChange= @strChange +','+ltrim(rtrim(column_name)) FROM
INFORMATION_SCHEMA.COLUMNS where table_name =@table and
ordinal_position = 7+@position
end
if (@b & 128 ) 8 begin
--print 8+@position
select @strChange= @strChange +','+ltrim(rtrim(column_name)) FROM
INFORMATION_SCHEMA.COLUMNS where table_name =@table and
ordinal_position = 8+@position
end

set @position = @position+ 8
set @i = @i+1


end
Avatar
john
Merci à tous

"Med Bouchenafa" wrote in message
news:%
Dans un trigger, la caluse IF COLUMNS_UPDATED() permet de savoir les
colonnes modifiées
Voir Aide En ligne pour plus de détails

--
Bien cordialement
Med Bouchenafa

"patrick" wrote in message
news:uhgOTd%
> Bonjour,
>
> Existe-t-il un moyen de connaitre les champs d'une table qui ont été
> modifiés par un UPDATE ?
> Le but étant de "tracer" les modifications sur certaines colonnes d'une
> table
>
> Merci
>
>