0

We have client data in our database that comes with ID(OrangeCustID), I am trying to autogenerate myCompanyID to each customer apart from the OrangeCustID and link it to the other tables and have it for our internal queries from SQL Server database.

Could someone please suggest how to achieve this?

Below is the sample table

enter image description here

Dale K
  • 25,246
  • 15
  • 42
  • 71
SMR
  • 401
  • 4
  • 15
  • Please clarify what you mean by "autogenerate mycompnayID to each customer apart from the OrangeCustID". Perhaps augment your table with whatever additional data you need, and explain the requirements. – Bill Jetzer Oct 22 '21 at 19:12
  • As per the question guide, please do not post images of code, data, error messages, etc. - copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text. – Dale K Oct 22 '21 at 21:36

1 Answers1

2

Just use a primary Key with identity column. When you insert the external data to the table SQL will generate the InternalId automatically.

CREATE TABLE dbo.MyTableName (
  InternalId INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
  OrangeCustID INT NOT NULL,
  Name NVARCHAR(250),
  Gender NVARCHAR(1),
  Order NVARCHAR(250),
  Cost INT
)