dimanche 28 juin 2015

SQL Server : stored procedure, if exists insert into another table

I need to write a Transact-SQL script in which I am creating 2 tables, Test and Error_log.

Test contains the following columns:

  • Id int NOT NULL PRIMARY KEY
  • Test_column nvarchar(10)

Error_log contains the following columns:

  • Id int NOT NULL PRIMARY KEY IDENTITY
  • DATA nvarchar (10)
  • Error_description varchar (500)

I need to write a stored procedure which will insert values into the Test table (for example 1, 1) and if I were to run it again, it would see that there is a duplicate record and then insert it into the Error_log table instead with an error description (hoping this is built in).

Any help would be greatly appreciated as I am a complete novice to SQL Server.

Aucun commentaire:

Enregistrer un commentaire