unique column in table

Vineet S 1,070 Reputation points
2024-07-06T02:21:59.06+00:00

HI,

merging table1 in table2

merge into table2 using table1 on table.col1=table2.col1

when not match then insert

how to add unique column with auto increament number and not null in table like

uniquenumner; Name;'

001 Test1

003 Testg2

Azure SQL Database
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,977 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,652 questions
{count} votes

Accepted answer
  1. LiHongMSFT-4306 27,961 Reputation points
    2024-07-08T02:30:41.6133333+00:00

    Hi @Vineet S

    how to add unique column with auto increament number and not null in table

    Add a new column ID that is unique and auto-incrementing:

    ALTER TABLE YourTable ADD ID INT IDENTITY(1,1) PRIMARY KEY;
    

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.