title: how to avoid inserting duplicate records in table type sql server
body: <p>i have this query for insert list of data in table 
  and now i want avoid insert duplicate records
  how i can do it in my code?</p>
  
  <p>please help me</p>
  
  <pre><code>-- Create a table type to match your input parameters
  CREATE TYPE IdNameTable AS TABLE 
  ( ID INT, Name NVARCHAR(50) );
  GO
  
  -- change your stored procedure to accept such a table type parameter
  ALTER PROCEDURE [dbo].[Register]
      @Values IdNameTable READONLY
  AS
  BEGIN
      BEGIN TRY
          INSERT INTO dbo.Group (Id, Name) 
            -- get the values from the table type parameter
            SELECT 
               Id, Name
            FROM
               @Values
  
          SELECT 0
      END TRY
      BEGIN CATCH
          SELECT -1
      END CATCH
  END
  GO
  </code></pre>