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

MS SQL Server Discussion :

[SQL-SEVER2005] Gestion des erreurs pour les requêtes


Sujet :

MS SQL Server

  1. #1
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2003
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 274
    Points : 372
    Points
    372
    Par défaut [SQL-SEVER 2000] Gestion des erreurs pour les requêtes
    Bonjour à toutes et tous,

    J'aimerais savoir s'il est possible de créer une instruction du genre vba :
    But :
    J'ai des requêtes SQL qui peuvent me retourner un message d'erreur dont le level est de niveau 16 mais pour lesquelles on peut quand même continuer sans que cela ne pose de problèmes pour la suite de mon travail.

    J'aimerais donc pouvoir sauter ces erreurs et continuer les requêtes suivantes.

    Je sais que l'on peut utiliser la variable @@ERROR mais comment ?

    Savez-vous si cela est possible ?

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

    Informations forums :
    Inscription : Octobre 2006
    Messages : 381
    Points : 231
    Points
    231
    Par défaut
    C'est peut etre ca qu'il te faut ?
    Sinon je sais que c'est possible sur DTS mais c'est pas pratique (et surtout y'a plus DTS sur 2005, c'est un nouvel outil, mais je connais pas du tout : / )

  3. #3
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2003
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 274
    Points : 372
    Points
    372
    Par défaut
    Merci NOX mais malheureusement j'avais déjà regardé de ce côté là.

    En fait, j'aimerais faire des ALTER sur des tables pour supprimer ou remettre des contraintes mais si il me retourne une erreur de niveau 16 sur la requête -> passer cette requête ...

    Cela signifierait simplement que j'avais déjà supprimé ou mis à jour la requête sur la contrainte...

    Je ne sais pas si je suis clair ...

  4. #4
    Membre du Club
    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
    Points : 58
    Points
    58
    Par défaut
    Bonjour,
    Avez-vous essayez des blocs d'exception ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    Begin try
    ....
    end try
    begin catch
    ....
    end catch

  5. #5
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2003
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 274
    Points : 372
    Points
    372
    Par défaut
    Bonjour,

    Tu peux me tutoyer.

    Oui, en effet j'ai essayé ces blocs mais il m'affiche un message d'erreur lors de la compilation :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    BEGIN TRY
    	ALTER TABLE COM_USER.INVESTMENT
     		DROP CONSTRAINT FK_INVESTME_ASSC_22_INVESTME
    END TRY
    BEGIN CATCH
    	PRINT 'OK'
    END CATCH
    Erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Msg 170, Level 15, State 1, Procedure SUPPRESS_YEAR_OF_FUND, Line 43
    Line 43: Incorrect syntax near 'TRY'.
    Apparemment il ne connaît pas la syntaxe BEGIN TRY

  6. #6
    Expert confirmé
    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
    Points : 4 043
    Points
    4 043
    Par défaut
    Bonjour,

    Le code TRY CATCH que tu postes est correct. Peux-tu poster toute la sproc SUPPRESS_YEAR_OF_FUND ?

  7. #7
    Membre du Club
    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
    Points : 58
    Points
    58
    Par défaut
    tu es bien en version 2005 ?

  8. #8
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2003
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 274
    Points : 372
    Points
    372
    Par défaut
    Oui je suis bien en SQL SERVER 2005

    Voici la procédure :
    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
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    USE DEV_COMMISION -- On choisi la base de données à utiliser
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
     
    --IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME = 'SUPPRESS_YEAR_OF_FUND' AND ROUTINE_SCHEMA = 'dbo')
    --	DROP PROCEDURE [dbo].SUPPRESS_YEAR_OF_FUND
    --GO
     
    --	AUTRE SOLUTION POUR TESTER L'EXISTANCE
    	IF OBJECT_ID(N'SUPPRESS_YEAR_OF_FUND', N'P') IS NOT NULL
    		DROP PROCEDURE SUPPRESS_YEAR_OF_FUND;
    	GO
     
    CREATE PROCEDURE SUPPRESS_YEAR_OF_FUND
    	-- PARAMETRES
    	@NUM_FOND INT, -- CONTIENT L'ID DU FOND
    	@NUM_ANNEE INT -- CONTIENT L'ANNEE QUE L'ON VEUT SUPPRIMER
    AS
    BEGIN
    	SET NOCOUNT ON;
    	SET XACT_ABORT ON;
     
        IF @NUM_ANNEE > 0 AND @NUM_FOND > 0 --  ON VERIFIE QUE L'ANNEE ET L'ID DU FOND SONT DONNES
    		BEGIN -- DEBUT DES TRAITEMENTS
    			-------------------------------
    			-- DECLARATION DES VARIABLES --
    			-------------------------------
    			DECLARE @IDFOND AS BIGINT
    			DECLARE @IDYEAR AS BIGINT
    			DECLARE @IDINVEST AS BIGINT
    			DECLARE @IDLIST AS BIGINT
    			DECLARE @IDEXPO AS BIGINT
    			DECLARE @IDEXPOTYPE AS BIGINT
    			DECLARE @IDDERIV AS BIGINT
    			DECLARE @IDDERIVTYPE AS BIGINT
    			DECLARE @IDUNDER AS BIGINT
    			DECLARE @IDUNDERTYPE AS BIGINT
    			DECLARE @IDSHORT AS BIGINT
    			DECLARE @IDSHORTTYPE AS BIGINT
    			DECLARE @IDPUT AS BIGINT
    			DECLARE @IDPUTTYPE AS BIGINT
    			DECLARE @ERREURS INT -- VARIABLE POUR LES ERREURS
    			DECLARE @LIGNES INT -- VARIABLE POUR LE NOMBRE DE LIGNES SUPPRIMEES
     
    			SET @ERREURS = 0
    			SET @LIGNES = 0
     
    			-------------------------------
    			-- ON RETIRE LES CONTRAINTES --
    			-------------------------------
    			--ALTER TABLE COM_USER.FUNDS 				DROP CONSTRAINT DF_FUNDS_ISIN
    			--ALTER TABLE COM_USER.FUNDS				DROP CONSTRAINT DF_FUNDS_LAUNCH_DATE
    			--ALTER TABLE COM_USER.FUNDS_YEAR 		DROP CONSTRAINT FK_FUNDS_YE_ASSC_24_FUNDS
    			BEGIN TRANSACTION A
    				ALTER TABLE COM_USER.INVESTMENT 		DROP CONSTRAINT FK_INVESTME_ASSC_22_INVESTME
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION A
    			ELSE
    				COMMIT TRANSACTION A
     
    			BEGIN TRANSACTION B
    				ALTER TABLE COM_USER.INVESTMENT 		DROP CONSTRAINT FK_INVESTME_ASSC_25_FUNDS_YE
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION B
    			ELSE
    				COMMIT TRANSACTION B
     
    			BEGIN TRANSACTION C
    				ALTER TABLE COM_USER.LISTING_STATUS 	DROP CONSTRAINT FK_LISTING__ASSC_23_INVESTME
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION C
    			ELSE
    				COMMIT TRANSACTION C
     
    			BEGIN TRANSACTION D
    				ALTER TABLE COM_USER.LISTING_STATUS 	DROP CONSTRAINT FK_LISTING__LISTING_T_LISTING_
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION D
    			ELSE
    				COMMIT TRANSACTION D
     
    			BEGIN TRANSACTION E
    				ALTER TABLE COM_USER.LISTING_TYPE 		DROP CONSTRAINT FK_LISTING_TYPE_INVESTMENT_TYPE
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION E
    			ELSE
    				COMMIT TRANSACTION E
     
    			BEGIN TRANSACTION F
    				ALTER TABLE COM_USER.DERIVATIVES		DROP CONSTRAINT FK_DERIVATI_ASSC_6_EXPOSURE
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION F
    			ELSE
    				COMMIT TRANSACTION F
     
    			BEGIN TRANSACTION G
    				ALTER TABLE COM_USER.DERIVATIVES		DROP CONSTRAINT FK_DERIVATI_ASSC_7_DERIVATI
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION G
    			ELSE
    				COMMIT TRANSACTION G
     
    			BEGIN TRANSACTION H
    				ALTER TABLE COM_USER.DERIVATIVES_TYPE 	DROP CONSTRAINT FK_DERIVATI_ASSC_19_EXPOSURE
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION H
    			ELSE
    				COMMIT TRANSACTION H
     
    			BEGIN TRANSACTION I
    			--ALTER TABLE COM_USER.DERIVATIVES_TYPE 	DROP CONSTRAINT DF_DERIVATIVES_TYPE_ID_GROUP
    				ALTER TABLE COM_USER.EXPOSURE 			DROP CONSTRAINT FK_EXPOSURE_EXPOSURE__EXPOSURE 
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION I
    			ELSE
    				COMMIT TRANSACTION I
     
    			BEGIN TRANSACTION J
    				ALTER TABLE COM_USER.EXPOSURE			DROP CONSTRAINT FK_EXPOSURE_EXPOSURE__LISTING_
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION J
    			ELSE
    				COMMIT TRANSACTION J
     
    			BEGIN TRANSACTION K
    				ALTER TABLE COM_USER.EXPOSURE_TYPE 		DROP CONSTRAINT FK_EXPOSURE_ASSC_18_LISTING_
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION K
    			ELSE
    				COMMIT TRANSACTION K
     
    			BEGIN TRANSACTION L
    				ALTER TABLE COM_USER.PUT_CALL			DROP CONSTRAINT FK_PUT_CALL_ASSC_15_SHORT_LO
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION L
    			ELSE
    				COMMIT TRANSACTION L
     
    			BEGIN TRANSACTION M
    				ALTER TABLE COM_USER.PUT_CALL 			DROP CONSTRAINT FK_PUT_CALL_ASSC_16_PUT_CALL
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION M
    			ELSE
    				COMMIT TRANSACTION M
     
    			BEGIN TRANSACTION N
    				ALTER TABLE COM_USER.PUT_CALL_TYPE 		DROP CONSTRAINT FK_PUT_CALL_ASSC_17_SHORT_LO
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION N
    			ELSE
    				COMMIT TRANSACTION N
     
    			BEGIN TRANSACTION O
    				ALTER TABLE COM_USER.SHORT_LONG			DROP CONSTRAINT FK_SHORT_LO_ASSC_12_UNDERLYI
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION O
    			ELSE
    				COMMIT TRANSACTION O
     
    			BEGIN TRANSACTION P
    				ALTER TABLE COM_USER.SHORT_LONG 		DROP CONSTRAINT FK_SHORT_LO_ASSC_13_SHORT_LO
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION P
    			ELSE
    				COMMIT TRANSACTION P
     
    			BEGIN TRANSACTION Q
    				ALTER TABLE COM_USER.SHORT_LONG_TYPE 	DROP CONSTRAINT FK_SHORT_LO_ASSC_21_UNDERLYI
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION Q
    			ELSE
    				COMMIT TRANSACTION Q
     
    			BEGIN TRANSACTION R
    				ALTER TABLE COM_USER.UNDERLYING 		DROP CONSTRAINT FK_UNDERLYI_ASSC_10_UNDERLYI
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION R
    			ELSE
    				COMMIT TRANSACTION R
     
    			BEGIN TRANSACTION S
    				ALTER TABLE COM_USER.UNDERLYING			DROP CONSTRAINT FK_UNDERLYI_ASSC_9_DERIVATI
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION S
    			ELSE
    				COMMIT TRANSACTION S
     
    			BEGIN TRANSACTION T
    				ALTER TABLE COM_USER.UNDERLYING_TYPE 	DROP CONSTRAINT FK_UNDERLYI_ASSC_20_DERIVATI
    			IF @@ERROR = 16
    				ROLLBACK TRANSACTION T
    			ELSE
    				COMMIT TRANSACTION T
     
     
    			-- OUVERTURE D'UN CURSEUR
    			DECLARE REC1 CURSOR FOR
    					-- LE SELECT VA RECUPERER TOUTES LES DONNEES DANS TOUTES LES TABLES
    					SELECT FOND.ID_FUNDS as 'FOND', 
    						ANNEE_FOND.ID_YEAR AS 'ANNEE', 
    						INVEST.ID_INVESTMENT AS 'INVEST', 
    						LISTING.ID_LISTING AS 'LISTING', 
    						EXPOSURE.ID_EXPOSURE AS 'EXPOSURE',
    						EXPOTYPE.ID_EXPOSURE_TYPE AS 'EXPO TYPE',
    						DERIV.ID_DERIVATIVES AS 'DERIV',
    						DERIVTYPE.ID_DERIVATIVES_TYPE AS 'DERIV TYPE',
    						UNDER.ID_UNDERLYING AS 'UNDER',
    						UNDERTYPE.ID_UNDERLYING_TYPE AS 'UNDER TYPE',
    						SHORT.ID_SHORT_LONG AS 'SHORT',
    						SHORTTYPE.ID_SHORT_LONG_TYPE AS 'SHORT TYPE',
    						PUT.ID_PUT_CALL AS 'PUT CALL',
    						PUTTYPE.ID_PUT_CALL_TYPE AS 'PUT CALL TYPE'
    					FROM	
    						(((((((((((((COM_USER.FUNDS AS FOND LEFT JOIN COM_USER.FUNDS_YEAR AS ANNEE_FOND ON FOND.ID_FUNDS = ANNEE_FOND.ID_FUNDS)
    							LEFT JOIN COM_USER.INVESTMENT AS INVEST ON ANNEE_FOND.ID_YEAR = INVEST.ID_YEAR)
    							LEFT JOIN COM_USER.LISTING_STATUS AS LISTING ON INVEST.ID_INVESTMENT = LISTING.ID_INVESTMENT)
    							LEFT JOIN COM_USER.EXPOSURE AS EXPOSURE ON LISTING.ID_LISTING = EXPOSURE.ID_LISTING) 
    							LEFT JOIN COM_USER.EXPOSURE_TYPE AS EXPOTYPE ON EXPOSURE.ID_EXPOSURE_TYPE = EXPOTYPE.ID_EXPOSURE_TYPE)
    							LEFT JOIN COM_USER.DERIVATIVES AS DERIV ON EXPOSURE.ID_EXPOSURE = DERIV.ID_EXPOSURE)
    							LEFT JOIN COM_USER.DERIVATIVES_TYPE AS DERIVTYPE 
    								ON (EXPOTYPE.ID_EXPOSURE_TYPE = DERIVTYPE.ID_EXPOSURE_TYPE AND DERIV.ID_DERIVATIVES_TYPE = DERIVTYPE.ID_DERIVATIVES_TYPE))
    							LEFT JOIN COM_USER.UNDERLYING AS UNDER ON DERIV.ID_DERIVATIVES = UNDER.ID_DERIVATIVES)
    							LEFT JOIN COM_USER.UNDERLYING_TYPE AS UNDERTYPE ON UNDERTYPE.ID_UNDERLYING_TYPE = UNDER.ID_UNDERLYING_TYPE)
    							LEFT JOIN COM_USER.SHORT_LONG AS SHORT ON UNDER.ID_UNDERLYING = SHORT.ID_UNDERLYING)
    							LEFT JOIN COM_USER.SHORT_LONG_TYPE AS SHORTTYPE
    								ON (SHORT.ID_SHORT_LONG_TYPE = SHORTTYPE.ID_SHORT_LONG_TYPE AND SHORTTYPE.ID_UNDERLYING_TYPE = UNDERTYPE.ID_UNDERLYING_TYPE))
    							LEFT JOIN COM_USER.PUT_CALL_TYPE AS PUTTYPE ON SHORTTYPE.ID_SHORT_LONG_TYPE = PUTTYPE.ID_SHORT_LONG_TYPE))
    							LEFT JOIN COM_USER.PUT_CALL AS PUT
    								ON (SHORT.ID_SHORT_LONG = PUT.ID_SHORT_LONG AND PUTTYPE.ID_PUT_CALL_TYPE = PUT.ID_PUT_CALL_TYPE)
    					WHERE FOND.ID_FUNDS = @NUM_FOND 
    							AND FOND.ID_FUNDS = ANNEE_FOND.ID_FUNDS 
    							AND ANNEE_FOND.ID_YEAR = (SELECT ID_YEAR FROM COM_USER.FUNDS_YEAR WHERE ID_FUNDS = @NUM_FOND AND ANNEE = @NUM_ANNEE)
    					ORDER BY INVEST.ID_INVESTMENT
    			FOR UPDATE --  N'EST PAS OBLIGATOIRE CAR PAR DEFAUT : DECLARE curseur CURSOR FOR qry FOR (UPDATE¦READ-ONLY)
     
    			OPEN REC1 -- OUVERTURE DU RECORD
     
    			-- ON RECUPERE LES DONNEES DU RECORD
    			FETCH REC1 INTO @IDFOND, @IDYEAR, @IDINVEST, @IDLIST, @IDEXPO, @IDEXPOTYPE,
    					@IDDERIV, @IDDERIVTYPE, @IDUNDER, @IDUNDERTYPE, @IDSHORT, @IDSHORTTYPE,
    					@IDPUT, @IDPUTTYPE
     
    			-- ON BOUCLE SUR TOUS LES RECORDS
    			WHILE @@FETCH_STATUS = 0
    				BEGIN
    					---------------------------------------------------
    					-- EFFACEMENT DES DONNEES DANS TOUTES LES TABLES --
    					---------------------------------------------------
    					IF @IDPUT IS NOT NULL
    						BEGIN
    							DELETE
    							FROM COM_USER.PUT_CALL
    							WHERE ID_PUT_CALL_TYPE = @IDPUTTYPE
    								AND @IDSHORT = ID_SHORT_LONG							
    						END
    					IF @IDPUTTYPE IS NOT NULL
    						BEGIN
    							DELETE
    							FROM COM_USER.PUT_CALL_TYPE
    							WHERE @IDSHORTTYPE = ID_SHORT_LONG_TYPE
    						END
    					IF @IDSHORTTYPE IS NOT NULL
    						BEGIN
    							DELETE
    							FROM COM_USER.SHORT_LONG_TYPE
    							WHERE @IDSHORTTYPE = COM_USER.SHORT_LONG_TYPE.ID_SHORT_LONG_TYPE
    								AND  COM_USER.SHORT_LONG_TYPE.ID_UNDERLYING_TYPE = @IDUNDERTYPE
    						END
    					IF @IDSHORT IS NOT NULL
    						BEGIN
    							DELETE
    							FROM COM_USER.SHORT_LONG
    							WHERE @IDUNDER = COM_USER.SHORT_LONG.ID_UNDERLYING
    						END
    					IF @IDUNDERTYPE IS NOT NULL
    						BEGIN
    							DELETE
    							FROM COM_USER.UNDERLYING_TYPE
    							WHERE COM_USER.UNDERLYING_TYPE.ID_UNDERLYING_TYPE = @IDUNDERTYPE
    						END
    					IF @IDUNDER IS NOT NULL
    						BEGIN
    							DELETE
    							FROM COM_USER.UNDERLYING
    							WHERE @IDDERIV = COM_USER.UNDERLYING.ID_DERIVATIVES
    						END
    					IF @IDDERIVTYPE IS NOT NULL
    						BEGIN
    							DELETE
    							FROM COM_USER.DERIVATIVES_TYPE
    							WHERE @IDEXPOTYPE = COM_USER.DERIVATIVES_TYPE.ID_EXPOSURE_TYPE
    								AND @IDDERIVTYPE = COM_USER.DERIVATIVES_TYPE.ID_DERIVATIVES_TYPE
    						END
    					IF @IDDERIV IS NOT NULL
    						BEGIN
    							DELETE
    							FROM COM_USER.DERIVATIVES
    							WHERE @IDEXPO = COM_USER.DERIVATIVES.ID_EXPOSURE
    						END
    					IF @IDEXPOTYPE IS NOT NULL
    						BEGIN
    							DELETE
    							FROM COM_USER.EXPOSURE_TYPE
    							WHERE COM_USER.EXPOSURE_TYPE.ID_EXPOSURE_TYPE = @IDEXPOTYPE
    						END
    					IF @IDEXPO IS NOT NULL
    						BEGIN
    							DELETE
    							FROM COM_USER.EXPOSURE
    							WHERE @IDLIST = COM_USER.EXPOSURE.ID_LISTING
    						END
    					IF @IDLIST IS NOT NULL
    						BEGIN
    							DELETE
    							FROM COM_USER.LISTING_STATUS
    							WHERE @IDINVEST = COM_USER.LISTING_STATUS.ID_INVESTMENT
    						END
    					IF @IDINVEST IS NOT NULL
    						BEGIN
    							DELETE
    							FROM COM_USER.INVESTMENT
    							WHERE COM_USER.INVESTMENT.ID_YEAR = @IDYEAR
    						END
     
    					-- ON PASSE AU RECORD SUIVANT ET ON RECUPERE LES DONNEES
    					FETCH REC1 INTO @IDFOND, @IDYEAR, @IDINVEST, @IDLIST, @IDEXPO, @IDEXPOTYPE,
    						@IDDERIV, @IDDERIVTYPE, @IDUNDER, @IDUNDERTYPE, @IDSHORT, @IDSHORTTYPE,
    						@IDPUT, @IDPUTTYPE
     
    			END -- FIN DU WHILE @@FETCH_STATUS = 0
     
    			CLOSE REC1 -- FERMETURE DU RECORD
    			DEALLOCATE REC1 -- DESTRUCTION DE L'OBJET
     
    			------------------------------
    			-- SUPPRIMER L'ANNE DU FOND --
    			------------------------------
    			DELETE 
    			FROM COM_USER.FUNDS_YEAR
    			WHERE ID_YEAR = @IDYEAR
    				AND ID_FUNDS = @IDFOND
     
    			------------------------------
    			-- ON REMET LES CONTRAINTES --
    			------------------------------
     
    			-- FUNDS YEAR
    --			ALTER TABLE COM_USER.FUNDS_YEAR
    --				ADD CONSTRAINT FK_FUNDS_YE_ASSC_24_FUNDS 
    --					FOREIGN KEY (ID_FUNDS)
    --						REFERENCES COM_USER.FUNDS (ID_FUNDS);
    --			IF @@ERROR = 16
    --			ALTER TABLE COM_USER.FUNDS_YEAR CHECK CONSTRAINT FK_FUNDS_YE_ASSC_24_FUNDS
    --			IF @@ERROR = 16
     
    			-- DERIVATIVES
    			ALTER TABLE COM_USER.DERIVATIVES 
    				ADD CONSTRAINT FK_DERIVATI_ASSC_6_EXPOSURE 
    					FOREIGN KEY (ID_EXPOSURE)
    						REFERENCES COM_USER.EXPOSURE (ID_EXPOSURE)
    			IF @@ERROR = 16
    			ALTER TABLE COM_USER.DERIVATIVES
    				ADD CONSTRAINT FK_DERIVATI_ASSC_7_DERIVATI 
    					FOREIGN KEY (ID_DERIVATIVES_TYPE)
    						REFERENCES COM_USER.DERIVATIVES_TYPE (ID_DERIVATIVES_TYPE)
    			IF @@ERROR = 16
    			-- DERIVATIVES TYPE
    			ALTER TABLE COM_USER.DERIVATIVES_TYPE
    				ADD CONSTRAINT FK_DERIVATI_ASSC_19_EXPOSURE
    					FOREIGN KEY (ID_EXPOSURE_TYPE)
    						REFERENCES COM_USER.EXPOSURE_TYPE (ID_EXPOSURE_TYPE)
    			IF @@ERROR = 16
    			-- EXPOOSURE
    			ALTER TABLE COM_USER.EXPOSURE
    				ADD CONSTRAINT FK_EXPOSURE_EXPOSURE__EXPOSURE
    					FOREIGN KEY (ID_EXPOSURE_TYPE)
    						REFERENCES COM_USER.EXPOSURE_TYPE (ID_EXPOSURE_TYPE)
    			IF @@ERROR = 16
    			ALTER TABLE COM_USER.EXPOSURE
    				ADD CONSTRAINT FK_EXPOSURE_EXPOSURE__LISTING_ 
    					FOREIGN KEY (ID_LISTING)
    						REFERENCES COM_USER.LISTING_STATUS (ID_LISTING)
    			IF @@ERROR = 16
    			-- EXPOSURE TYPE
    			ALTER TABLE COM_USER.EXPOSURE_TYPE
    				ADD CONSTRAINT FK_EXPOSURE_ASSC_18_LISTING_ 
    					FOREIGN KEY (ID_LISTING_TYPE)
    						REFERENCES COM_USER.LISTING_TYPE (ID_LISTING_TYPE)
    			IF @@ERROR = 16
    			-- INVESTMENT
    			ALTER TABLE COM_USER.INVESTMENT
    				ADD CONSTRAINT FK_INVESTME_ASSC_22_INVESTME 
    					FOREIGN KEY (ID_INVESTMENT_TYPE)
    						REFERENCES COM_USER.INVESTMENT_TYPE (ID_INVESTMENT_TYPE)
    			IF @@ERROR = 16
    			ALTER TABLE COM_USER.INVESTMENT
    				ADD CONSTRAINT FK_INVESTME_ASSC_25_FUNDS_YE 
    					FOREIGN KEY (ID_YEAR)
    						REFERENCES COM_USER.FUNDS_YEAR (ID_YEAR)
    			IF @@ERROR = 16
    			-- LISTING STATUS
    			ALTER TABLE COM_USER.LISTING_STATUS
    				ADD CONSTRAINT FK_LISTING__ASSC_23_INVESTME 
    					FOREIGN KEY (ID_INVESTMENT)
    						REFERENCES COM_USER.INVESTMENT (ID_INVESTMENT)
    			IF @@ERROR = 16
    			ALTER TABLE COM_USER.LISTING_STATUS
    				ADD CONSTRAINT FK_LISTING__LISTING_T_LISTING_ 
    					FOREIGN KEY (ID_LISTING_TYPE)
    						REFERENCES COM_USER.LISTING_TYPE (ID_LISTING_TYPE)
    			IF @@ERROR = 16
    			-- LISTING TYPE
    			ALTER TABLE COM_USER.LISTING_TYPE
    				ADD CONSTRAINT FK_LISTING_TYPE_INVESTMENT_TYPE 
    					FOREIGN KEY (ID_INVESTMENT_TYPE)
    						REFERENCES COM_USER.INVESTMENT_TYPE (ID_INVESTMENT_TYPE)
    			IF @@ERROR = 16
    			-- PUT CALL
    			ALTER TABLE COM_USER.PUT_CALL
    				ADD CONSTRAINT FK_PUT_CALL_ASSC_15_SHORT_LO 
    					FOREIGN KEY (ID_SHORT_LONG)
    						REFERENCES COM_USER.SHORT_LONG (ID_SHORT_LONG)
    			IF @@ERROR = 16
    			ALTER TABLE COM_USER.PUT_CALL
    				ADD CONSTRAINT FK_PUT_CALL_ASSC_16_PUT_CALL 
    					FOREIGN KEY (ID_PUT_CALL_TYPE)
    						REFERENCES COM_USER.PUT_CALL_TYPE (ID_PUT_CALL_TYPE)
    			IF @@ERROR = 16
    			-- PUT CALL TYPE
    			ALTER TABLE COM_USER.PUT_CALL_TYPE
    				ADD CONSTRAINT FK_PUT_CALL_ASSC_17_SHORT_LO 
    					FOREIGN KEY (ID_SHORT_LONG_TYPE)
    						REFERENCES COM_USER.SHORT_LONG_TYPE (ID_SHORT_LONG_TYPE)
    			IF @@ERROR = 16
    			-- SHORT LONG
    			ALTER TABLE COM_USER.SHORT_LONG
    				ADD CONSTRAINT FK_SHORT_LO_ASSC_12_UNDERLYI 
    					FOREIGN KEY (ID_UNDERLYING)
    						REFERENCES COM_USER.UNDERLYING (ID_UNDERLYING)
    			IF @@ERROR = 16
    			ALTER TABLE COM_USER.SHORT_LONG
    				ADD CONSTRAINT FK_SHORT_LO_ASSC_13_SHORT_LO 
    					FOREIGN KEY (ID_SHORT_LONG_TYPE)
    						REFERENCES COM_USER.SHORT_LONG_TYPE (ID_SHORT_LONG_TYPE)
    			IF @@ERROR = 16
    			-- SHORT LONG TYPE
    			ALTER TABLE COM_USER.SHORT_LONG_TYPE
    				ADD CONSTRAINT FK_SHORT_LO_ASSC_21_UNDERLYI 
    					FOREIGN KEY (ID_UNDERLYING_TYPE)
    						REFERENCES COM_USER.UNDERLYING_TYPE (ID_UNDERLYING_TYPE)
    			IF @@ERROR = 16
    			-- UNDERLYING
    			ALTER TABLE COM_USER.UNDERLYING
    				ADD CONSTRAINT FK_UNDERLYI_ASSC_10_UNDERLYI 
    					FOREIGN KEY (ID_UNDERLYING_TYPE)
    						REFERENCES COM_USER.UNDERLYING_TYPE (ID_UNDERLYING_TYPE)
    			IF @@ERROR = 16
    			ALTER TABLE COM_USER.UNDERLYING
    				ADD CONSTRAINT FK_UNDERLYI_ASSC_9_DERIVATI 
    					FOREIGN KEY (ID_DERIVATIVES)
    						REFERENCES COM_USER.DERIVATIVES (ID_DERIVATIVES)
    			IF @@ERROR = 16
    			-- UNDERLYING TYPE
    			ALTER TABLE COM_USER.UNDERLYING_TYPE
    				ADD CONSTRAINT FK_UNDERLYI_ASSC_20_DERIVATI 
    					FOREIGN KEY (ID_DERIVATIVES_TYPE)
    						REFERENCES COM_USER.DERIVATIVES_TYPE (ID_DERIVATIVES_TYPE)
     
     
    		END -- FIN DES TRAITEMENTS IF @NUM_ANNEE > 0 AND @NUM_FOND > 0
    	ELSE -- SI ON L'UNE DES DEUX, OU LES DEUX VARIABLES NE SONT PAS MENTIONNEES
    		RETURN -1 -- ON RETOURNE UNE VALEUR FICTIVE
    END
    ATTENTION : Mes BEGIN TRAN A -> T sont des tests car je n'arrive pas à trouver une solution.
    Idem pour la partie du bas où je remets les contraintes sur la base ....

  9. #9
    Expert confirmé
    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
    Points : 4 043
    Points
    4 043
    Par défaut
    Bon, merci, mais où voulais tu mettre ton TRY CATCH ? Je n'en vois aucun ?

    Une petite info sur les transactions : un ROLLBACK annule toujours tout, donc c'est inutile de lui donner un nom de transaction.
    Tu n'as pas besoin de supprimer les contraintes, si tu supprimes dans l'ordre.
    Il vaut mieux utiliser une table temporaire qu'un curseur, ou simplement de configurer tes contraintes de clés étrangères pour faire de la cascade en suppression.

  10. #10
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2003
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 274
    Points : 372
    Points
    372
    Par défaut
    Les TRY CATCH je les ai essayé au début lors de ma suppression des contraintes et également à la remise des contraintes mais cela ne fonctionnait pas.

    Je n'ai pas le droit de modifier les contraintes car elles ont été imposées ....
    -> mon gros soucis car cela aurait été plus simple de pouvoir faire un delete en cascade ....
    C'est pour cela que je dois faire chaque effacement manuellement.

    Utiliser une table temporaire au lieu d'un curseur mais comment faire ?

    Pourrais-tu nettoyer mon code et me montrer comment faire les TRY CATCH ainsi que la table temporaire au lieu du curseur ?
    Si tu en as le temps bien entendu ...

  11. #11
    Modérateur

    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Janvier 2005
    Messages
    5 826
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2005
    Messages : 5 826
    Points : 12 371
    Points
    12 371
    Par défaut
    Bonjour Eagleleader,

    Voici une piste qui ne comprend pas la suppression des contraintes que tu fais à la fin:

    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
     
    USE DEV_COMMISION -- On choisi la base de donn?es ? utiliser
    GO
     
    IF OBJECT_ID(N'SUPPRESS_YEAR_OF_FUND', N'P') IS NOT NULL
    	DROP PROCEDURE SUPPRESS_YEAR_OF_FUND;
    GO
     
    CREATE PROCEDURE SUPPRESS_YEAR_OF_FUND
    	-- PARAMETRES
    	@NUM_FOND INT, -- CONTIENT L'ID DU FOND
    	@NUM_ANNEE INT -- CONTIENT L'ANNEE QUE L'ON VEUT SUPPRIMER
    AS
    BEGIN
    	SET NOCOUNT ON;
    	SET XACT_ABORT ON;
     
        IF @NUM_ANNEE > 0 AND @NUM_FOND > 0 --  ON VERIFIE QUE L'ANNEE ET L'ID DU FOND SONT DONNES
    		BEGIN -- DEBUT DES TRAITEMENTS
    			-------------------------------
    			-- DECLARATION DES VARIABLES --
    			-------------------------------
    			DECLARE @ERREURS INT -- VARIABLE POUR LES ERREURS
    			DECLARE @LIGNES INT -- VARIABLE POUR LE NOMBRE DE LIGNES SUPPRIMEES
     
    			SET @ERREURS = 0
    			SET @LIGNES = 0
     
    			-------------------------------
    			-- ON RETIRE LES CONTRAINTES --
    			-------------------------------
    			--ALTER TABLE COM_USER.FUNDS 				DROP CONSTRAINT DF_FUNDS_ISIN
    			--ALTER TABLE COM_USER.FUNDS				DROP CONSTRAINT DF_FUNDS_LAUNCH_DATE
    			--ALTER TABLE COM_USER.FUNDS_YEAR 		DROP CONSTRAINT FK_FUNDS_YE_ASSC_24_FUNDS
     
    			-- Ici on peut repeter ce bloc pour toutes les contraintes			
    			BEGIN TRY
    				ALTER TABLE maTable
    				DROP CONSTRAINT maContrainte
    			END TRY
    			BEGIN CATCH
    				DECLARE @ERR VARCHAR(1024);
    				SET @ERR = 'Erreur lors de la suppression de la contrainte FK_INVESTME_ASSC_22_INVESTME : ' + ERROR_MESSAGE();
    				PRINT @ERR;
    			END CATCH;
     
    			-- Creation d'une table temporaire de travail pour la suppression des donnees			
    			SELECT
    				FOND.ID_FUNDS AS 'FOND', 
    				ANNEE_FOND.ID_YEAR AS 'ANNEE', 
    				INVEST.ID_INVESTMENT AS 'INVEST', 
    				LISTING.ID_LISTING AS 'LISTING', 
    				EXPOSURE.ID_EXPOSURE AS 'EXPOSURE',
    				EXPOTYPE.ID_EXPOSURE_TYPE AS 'EXPO TYPE',
    				DERIV.ID_DERIVATIVES AS 'DERIV',
    				DERIVTYPE.ID_DERIVATIVES_TYPE AS 'DERIV TYPE',
    				UNDER.ID_UNDERLYING AS 'UNDER',
    				UNDERTYPE.ID_UNDERLYING_TYPE AS 'UNDER TYPE',
    				SHORT.ID_SHORT_LONG AS 'SHORT',
    				SHORTTYPE.ID_SHORT_LONG_TYPE AS 'SHORT TYPE',
    				PUT.ID_PUT_CALL AS 'PUT CALL',
    				PUTTYPE.ID_PUT_CALL_TYPE AS 'PUT CALL TYPE'
    			INTO #REC1
    			FROM
    				COM_USER.FUNDS AS FOND
    				LEFT JOIN COM_USER.FUNDS_YEAR AS ANNEE_FOND
    					ON FOND.ID_FUNDS = ANNEE_FOND.ID_FUNDS
    				LEFT JOIN COM_USER.INVESTMENT AS INVEST
    					ON ANNEE_FOND.ID_YEAR = INVEST.ID_YEAR
    				LEFT JOIN COM_USER.LISTING_STATUS AS LISTING
    					ON INVEST.ID_INVESTMENT = LISTING.ID_INVESTMENT
    				LEFT JOIN COM_USER.EXPOSURE AS EXPOSURE
    					ON LISTING.ID_LISTING = EXPOSURE.ID_LISTING 
    				LEFT JOIN COM_USER.EXPOSURE_TYPE AS EXPOTYPE
    					ON EXPOSURE.ID_EXPOSURE_TYPE = EXPOTYPE.ID_EXPOSURE_TYPE
    				LEFT JOIN COM_USER.DERIVATIVES AS DERIV
    					ON EXPOSURE.ID_EXPOSURE = DERIV.ID_EXPOSURE
    				LEFT JOIN COM_USER.DERIVATIVES_TYPE AS DERIVTYPE 
    					ON EXPOTYPE.ID_EXPOSURE_TYPE = DERIVTYPE.ID_EXPOSURE_TYPE
    					AND DERIV.ID_DERIVATIVES_TYPE = DERIVTYPE.ID_DERIVATIVES_TYPE
    				LEFT JOIN COM_USER.UNDERLYING AS UNDER
    					ON DERIV.ID_DERIVATIVES = UNDER.ID_DERIVATIVES
    				LEFT JOIN COM_USER.UNDERLYING_TYPE AS UNDERTYPE
    					ON UNDERTYPE.ID_UNDERLYING_TYPE = UNDER.ID_UNDERLYING_TYPE
    				LEFT JOIN COM_USER.SHORT_LONG AS SHORT
    					ON UNDER.ID_UNDERLYING = SHORT.ID_UNDERLYING
    				LEFT JOIN COM_USER.SHORT_LONG_TYPE AS SHORTTYPE
    					ON SHORT.ID_SHORT_LONG_TYPE = SHORTTYPE.ID_SHORT_LONG_TYPE
    					AND SHORTTYPE.ID_UNDERLYING_TYPE = UNDERTYPE.ID_UNDERLYING_TYPE
    				LEFT JOIN COM_USER.PUT_CALL_TYPE AS PUTTYPE
    					ON SHORTTYPE.ID_SHORT_LONG_TYPE = PUTTYPE.ID_SHORT_LONG_TYPE
    				LEFT JOIN COM_USER.PUT_CALL AS PUT
    					ON SHORT.ID_SHORT_LONG = PUT.ID_SHORT_LONG
    					AND PUTTYPE.ID_PUT_CALL_TYPE = PUT.ID_PUT_CALL_TYPE
    			WHERE FOND.ID_FUNDS = @NUM_FOND 
    			AND FOND.ID_FUNDS = ANNEE_FOND.ID_FUNDS 
    			AND ANNEE_FOND.ID_YEAR = (SELECT ID_YEAR FROM COM_USER.FUNDS_YEAR WHERE ID_FUNDS = @NUM_FOND AND ANNEE = @NUM_ANNEE)
    			ORDER BY INVEST.ID_INVESTMENT
     
    			---------------------------------------------------
    			-- EFFACEMENT DES DONNEES DANS TOUTES LES TABLES --
    			---------------------------------------------------
     
    			-- Il est preferable de gerer les supressions de donnees de facon ensembliste
    			-- On peut donc faire un DELETE en utilisant un JOIN (Les WHERE et AND du curseur) 
    			-- et restreindre le jeu de donnees a supprimer avec  un WHERE (Les tests IF du curseur)
    			DELETE FROM COM_USER.PUT_CALL
    			FROM COM_USER.PUT_CALL TABLE_A
    			JOIN #REC1 ON TABLE_A.ID_PUT_CALL_TYPE = #REC1.ID_PUT_CALL_TYPE
    						AND TABLE_A.ID_SHORT_LONG = #REC1.ID_SHORT_LONG
    			WHERE #REC1.ID_FUNDS IS NOT NULL
     
    			------------------------------
    			-- SUPPRIMER L'ANNE DU FOND --
    			------------------------------
    			DELETE 
    			FROM COM_USER.FUNDS_YEAR
    			WHERE ID_YEAR = @IDYEAR
    				AND ID_FUNDS = @IDFOND
    Regarde dans les commentaires du code pour voir ce que j'ai modifié.
    L'utilisatation de curseurs comme je te l'ai dit dans une autre discussion est à proscrire, parce que c'est lent parce que ce n'est pas ensembliste.
    Tu peux les utiliser par exemple quand tu as une série d'appels à une procédure stockée à faire

    Reviens vers nous si tu es bloqué

  12. #12
    Expert confirmé
    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
    Points : 4 043
    Points
    4 043
    Par défaut
    Hello,

    Pour les contraintes, vraiment, il est inutile de les supprimer. Tu dois simplement organiser tes DELETE dans le bon ordre. En premier, la table qui est la plus externe, cad celle qui n'est référencée par aucune autre table, et ensuite tu effaces en remontant.

  13. #13
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2003
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 274
    Points : 372
    Points
    372
    Par défaut
    Bonjour Elsuket, rudib,

    Je viens d'avoir une information -> je suis en SQL serveur 2000
    Désolé mais le DBA n'étant pas là avant, je n'ai pu avoir cette info ...
    Je comprends mieux pourquoi le BEGIN TRY CATCH ne fonctionnait pas ...

    Elsuket, je vais essayer de comprendre et d'adapter ta solution de table temporaire ...
    Petites questions : Comment dois-je déclarer REC1 ? Comment, après les traitements, supprimer cette table temporaire ?
    -- OK, Je viens de trouver sur le net la syntaxe et ce qu'elle représente.
    Je vais me pencher maintenant sur l'utilisation de cette table temporaire REC1 ...

    Rudib, saches que j'ai tenté d'effacer de la plus externe vers l'interne mais je n'ai pas pu le faire.
    Je vais tenter de repérer le message que j'obtenais ...

  14. #14
    Expert confirmé
    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
    Points : 4 043
    Points
    4 043
    Par défaut
    Citation Envoyé par eagleleader Voir le message
    Je viens d'avoir une information -> je suis en SQL serveur 2000
    Pour info, tu peux le savoir sans ton DBA :

  15. #15
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2003
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 274
    Points : 372
    Points
    372
    Par défaut
    Merci pour l'information ...
    En fait je commence juste à utiliser les SQl et SQL SERVER ... J'ai commencé la semaine passée, voilà pourquoi je ne savais pas en quelle version j'étais.

  16. #16
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2003
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 274
    Points : 372
    Points
    372
    Par défaut
    Rudi,

    Voici ce que j'obtiens, lors je veux supprimer dans la table la plus externe :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Msg 547, Level 16, State 0, Line 1
    DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_SHORT_LO_ASSC_13_SHORT_LO'. 
    The conflict occurred in database 'DEV_COMMISION', table 'SHORT_LONG', column 'ID_SHORT_LONG_TYPE'.
    The statement has been terminated.
     
    (0 row(s) affected)
    Et voici la requête utilisée :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    DELETE
    FROM COM_USER.SHORT_LONG_TYPE
    WHERE ID_SHORT_LONG_TYPE = 4
    	AND ID_UNDERLYING_TYPE = 4

  17. #17
    Expert confirmé
    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
    Points : 4 043
    Points
    4 043
    Par défaut
    Cela veut simplement dire que tu as une référence à des ID_SHORT_LONG_TYPE = 4 dans la table SHORT_LONG.
    Il faut d'abord supprimer ces lignes dans la table SHORT_LONG.

    Si tu ne le fais pas et tu supprimes la contrainte de clé étrangère, cela signifie que tu te retrouves avec des orphelins dans SHORT_LONG

  18. #18
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2003
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 274
    Points : 372
    Points
    372
    Par défaut
    C'est exact ...
    Ceci est du aux contraintes.
    Je pense que je suis obligé de faire des tests d'effacement dans chacune des tables afin de voir quels records il effacera automatiquement dans les autres tables : ceci pour effacer progressivement toutes les informations...

    Je vous tiens au courant ...

  19. #19
    Expert confirmé
    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
    Points : 4 043
    Points
    4 043
    Par défaut
    Citation Envoyé par eagleleader Voir le message
    Ceci est du aux contraintes.
    Je pense que je suis obligé de faire des tests d'effacement dans chacune des tables
    Ca tu le fais une fois pour toute, en connaissant le diagramme de ta base de données, et tu écris le code en conséquence.

  20. #20
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2003
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 274
    Points : 372
    Points
    372
    Par défaut
    Oui,

    J'ai choppé le diagramme et j'ai suivi l'effacement depuis le début de mes requêtes.
    Il ne me reste qu'une chose qui me bloque et qui m'as fait changer de trajectoire dans mon développement.

    Une table me pose problème :
    Lorsque je fais mes suppressions, tout se passe bien sauf dans une seule où il refuse de supprimer les enregistrements.

    J'explique :

    J'arrive à effacer toutes les données dans les tables sauf pour une seule table : COM_USER.EXPOSURE_TYPE

    Lorsque je vérifie les données suivantes (ici le nom et l'id dans les tables) :

    fond : 391
    annee : 2616
    investment : 5371
    listing_status : 3970
    exposure : 3141
    exposure type : 102

    Si je fais les requêtes de sélection dans les tables EXPO et EXPO T :
    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
    select *
    from COM_USER.INVESTMENT
    where id_year = 2616
     
    SELECT *
    FROM COM_USER.EXPOSURE
    WHERE ID_EXPOSURE_TYPE = 102
    	and ID_LISTING = 3970
     
    SELECT *
    FROM COM_USER.EXPOSURE
    WHERE ID_EXPOSURE = 3141
     
    SELECT *
    FROM COM_USER.EXPOSURE_TYPE
    WHERE ID_EXPOSURE_TYPE = 102
    Seule la dernière requête va me renvoyer une valeur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    102	53	NULL	Traded on regulated market
    102 -> ID EXPOSURE TYPE
    53 -> ID LISTING TYPE
    NULL et Traded... sont deux autres champs.

    Si je fais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    DELETE
    FROM COM_USER.EXPOSURE_TYPE
    WHERE ID_EXPOSURE_TYPE = 102
    J'obtiens :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Msg 547, Level 16, State 0, Line 1
    DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_EXPOSURE_EXPOSURE__EXPOSURE'. 
    The conflict occurred in database 'DEV_COMMISION', table 'EXPOSURE', column 'ID_EXPOSURE_TYPE'.
    The statement has been terminated.
    Pourtant, plus auncune donées ne correspond dans cette table EXPOSURE.
    Il reste par contre d'autre ID 102 dans cette table mais pour lesquels l'ID LISTING ne correspond pas à celui que l'on va supprimer ...

    Je ne sais pas si je suis clair ...

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Gestion des erreurs dans une requête "IF"
    Par tineighty dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 08/10/2007, 18h22
  2. Réponses: 2
    Dernier message: 28/02/2007, 13h13
  3. Gestion des erreurs pour runtime
    Par cbleas dans le forum Runtime
    Réponses: 1
    Dernier message: 09/12/2006, 14h18
  4. Réponses: 6
    Dernier message: 09/06/2006, 12h17

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