-2

I am building this project with SQL Server.

I need to create a Shop table, this shop (numbers) will include alphanumeric as the shop's identification number.

How do I create a table with alphanumeric primary key instead of using INT as data type? And will this table still increment like when using INT for the primary key?

philipxy
  • 14,867
  • 6
  • 39
  • 83
Okeke
  • 9
  • 2
  • 2
    A key column is not limited to integers. – Stu Jul 16 '22 at 19:43
  • You should not make your primary key a human relevant key. Use a regular indentity column for your primary key and have the shop code as a secondary identifier. – Dale K Jul 16 '22 at 21:06

2 Answers2

-1

As for the data type, you can use "nvarchar" to be able to deal with letters and numbers, for increment you have to do it manually (either in code or in a function in the database)

-3

You can use guid and below is how you define your primary column.

CREATE TABLE table_name
(
  id UNIQUEIDENTIFIER DEFAULT NEWID() PRIMARY KEY
);

Read more on guid here

GoonerForLife
  • 631
  • 2
  • 5