IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Développement SQL Server Discussion :

SQL Server 2005 - Probleme : Trigger non déclenché lors d'une insertion importante


Sujet :

Développement SQL Server

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    381
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 381
    Par défaut SQL Server 2005 - Probleme : Trigger non déclenché lors d'une insertion importante
    Bonjour à tous,

    j'ai un probleme avec un trigger qui m'embete depuis quelques jours :

    J'ai une base SQL et une table avec un trigger en INSERT/UPDATE. Tout marche bien lorsque j'insere une ligne ou deux, mais lorsque je fais un import important (via DTSX), le trigger ne se déclenche qu'apres un certain nombre de lignes importées.

    Avez vous connaissances d'un bug de ce genre ? Y'a-t-il un contournement/solution possible ?

    Je ne sais pas si ma description du probleme est suffisante, n'hésitez pas s'il manque des indications.

  2. #2
    Membre Expert
    Avatar de rudib
    Homme Profil pro
    Fakir SQL Server & NoSQL
    Inscrit en
    Mai 2006
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Fakir SQL Server & NoSQL

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 573
    Par défaut
    Bonjour,

    Ton trigger est-il ensembliste ? Peux-tu poster son code ?

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    381
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 381
    Par défaut
    Voici mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
     
    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
     
    ALTER TRIGGER [x_lead_links_xml_imports]
       ON  [SYSADM].[X_Lead_Links]
       AFTER INSERT
    AS
    DECLARE 
     
    @LeaNrid DECIMAL(15,0),
    @cpt_nrid int,
    @test VARCHAR(50),
    @CompanyName VARCHAR(50),
    @CompanyPC VARCHAR(50),
    @ContactFN VARCHAR(50),
    @ContactLN VARCHAR(50),
    @ExistingCompany decimal, -- linked company/contact information
    @ExistingCompanyKN decimal,
    @ExistingContactFN decimal,
    @ExistingContactLN decimal,
    @TestExistingCompany varchar(10),
    @TestExistingContact varchar(10),
    @strTable varchar(3), --fctRID parameters
    @societe varchar(50),
    @societe_type varchar(50),
    @societe_city varchar(50),
    @societe_street varchar(50),
    @so0_nrid decimal,
    @societe_PC varchar(10),
    @personne varchar(50),
    @pe0_nrid decimal,
    @nrid decimal
     
     
    BEGIN
     
        SELECT @nrid = nrid, @LeaNrid = lea0_nrid, @CompanyName = societe_lead , @CompanyPC = societe_exist, @ContactFN = personne_lead, @ContactLN = personne_exist, @test = societe_street from inserted
     
            IF (@test = 'xml_trigger')
            BEGIN
     
                    SET @ExistingCompany = null
                    SET @ExistingCompanyKN = null
                    SET @ExistingContactFN = null
                    SET @ExistingContactLN = null
     
                    SET @ExistingCompany = (select top 1 nrid from sysadm.so0 where societe = @CompanyName and code_post = @CompanyPC and template is null)
                    SET @ExistingCompanyKN = (select top 1 nrid from sysadm.so0 where SOCIETE_2 = @CompanyName and code_post = @CompanyPC and template is null)
                    SET @ExistingContactFN = (select top 1 nrid from sysadm.pe0 where prenom = @ContactFN and template is null)
                    SET @ExistingContactLN = (select top 1 nrid from sysadm.pe0 where personne = @ContactLN and template is null)
     
            -- Insert data initialization
                    SET @TestExistingCompany=(select lay.message from sysadm.set_lay lay where lay.identify = 'No' and applic_id=100000000000001)
                    SET @TestExistingContact=(select lay.message from sysadm.set_lay lay where lay.identify = 'Ignore' and applic_id=100000000000001)
                    SET @societe=null
                    SET @so0_nrid=null
                    SET @personne=null
                    SET @pe0_nrid=null
                    SET @societe_PC=null
     
     
                    IF @ExistingCompany is not null
                    BEGIN
                            SET @TestExistingCompany=(select lay.message from sysadm.set_lay lay where lay.identify = 'Yes' and applic_id=100000000000001)
                            SET @societe=@CompanyName
                            SET @so0_nrid=@ExistingCompany
                            SET @societe_type=(select type from sysadm.so0 where nrid=@ExistingCompany)
                            SET @societe_city=(select loc from sysadm.so0 where nrid=@ExistingCompany)
                            SET @societe_street=(select adresse from sysadm.so0 where nrid=@ExistingCompany)
                            SET @societe_PC=@CompanyPC
                    END
                    ELSE IF @ExistingCompanyKN is not null
                    BEGIN
                            SET @TestExistingCompany=(select lay.message from sysadm.set_lay lay where lay.identify = 'Ignore' and applic_id=100000000000001)
                            SET @societe=@CompanyName
                            SET @so0_nrid=@ExistingCompany
                            SET @societe_type=(select type from sysadm.so0 where nrid=@ExistingCompany)
                            SET @societe_city=(select loc from sysadm.so0 where nrid=@ExistingCompany)
                            SET @societe_street=(select adresse from sysadm.so0 where nrid=@ExistingCompany)
                            SET @societe_PC=@CompanyPC
                    END
     
                    IF @ExistingContactFN is not null
                    BEGIN
                            IF @ExistingContactLN is not null
                            BEGIN
                                    SET @TestExistingContact=(select lay.message from sysadm.set_lay lay where lay.identify = 'Yes' and applic_id=100000000000001)
                                    SET @personne=@ContactFN + ' ' + @ContactLN
                                    SET @pe0_nrid=@ExistingContactLN
                            END
                            ELSE
                            BEGIN
                                    SET @TestExistingContact=(select lay.message from sysadm.set_lay lay where lay.identify = 'Ignore' and applic_id=100000000000001)
                                    SET @personne=@ContactFN + ' ' + (SELECT personne FROM sysadm.pe0 where nrid = @ExistingContactFN)
                                    SET @pe0_nrid=@ExistingContactLN
                            END
                    END
                    ELSE IF @ExistingContactLN is not null
                    BEGIN
                            SET @TestExistingContact=(select lay.message from sysadm.set_lay lay where lay.identify = 'Ignore' and applic_id=100000000000001)
                            SET @personne=(SELECT prenom FROM sysadm.pe0 where nrid = @ExistingContactFN) + ' ' + @ContactLN
                            SET @pe0_nrid=@ExistingContactLN
                    END
     
                    UPDATE sysadm.x_lead_links SET societe = @societe,
                                                   societe_exist = @TestExistingCompany,
                                                   so0_nrid = @so0_nrid,
                                                   societe_type =@societe_type,
                                                   societe_postalcode = @societe_PC,
                                                   societe_city = @societe_city,
                                                   societe_street = @societe_street,
                                                   personne_exist = @TestExistingContact,
                                                   personne = @personne,
                                                   personne_lead = (@ContactFN + ' ' + @ContactLN),
                                                   pe0_nrid = @pe0_nrid
                                                   where nrid = @nrid
     
            END
     
    END

  4. #4
    Membre éclairé
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    46
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Mai 2007
    Messages : 46
    Par défaut
    Bonjour,
    Ce code fonctionne au coup par coup. Pour des insertions en bloc, le select devrait être dans un curseur parcouru par le code afin de prendre en compte tous les enregistrements insérés.

  5. #5
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    381
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 381
    Par défaut
    Hm...je ne suis pas sur de comprendre.
    Je ne connais pas les "insertions en bloc". Le curseur va devoir parser la table INSERTED et traiter les lignes une par une ? C'est ca ?

  6. #6
    Membre éclairé
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    46
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Mai 2007
    Messages : 46
    Par défaut
    oui, c'est ça.

Discussions similaires

  1. SQL Server 2005 probleme de connextion avec la cmd isql
    Par Sniper37 dans le forum MS SQL Server
    Réponses: 1
    Dernier message: 14/12/2007, 15h45
  2. [SQL SERVER 2005] probleme basique
    Par barnet dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 12/06/2007, 16h17
  3. [SQL server 2005] Problème de tris avec notion Père-Fils
    Par pedrover dans le forum Langage SQL
    Réponses: 5
    Dernier message: 06/12/2006, 16h43
  4. SQL SERVER 2005 - Alter Trigger réactive le trigger ?
    Par Peck777 dans le forum Développement
    Réponses: 1
    Dernier message: 29/06/2006, 13h51
  5. [SQL SERVER 2005] Probleme variable local
    Par nashouille dans le forum MS SQL Server
    Réponses: 1
    Dernier message: 09/05/2006, 11h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo