SQL Server 2022 : Automatically Assign Record Identities
We know that social security number, employee ID or passport number are all unique numbers.
SQL Server has the capability to let the database engine automatically assign new unique identifies when new records are added. Let's do it.
First, select the table 'Customers' from my SQL server 2022's database 'Red30Tech', then right click the table name and select Design.
Now, drag the little triangle icon on the left of CustomerID to the top, click the Primary key icon, this column will be assigned as column with unique value for each row.
Save the design window and hover over to the table name again, right click and press 'Select Top 1000 Rows'.
Then we can see the SQL sever created the unique CustomerID automatically for each row.
Let's go back to Object Explorer, click the dbo.Customers table name, then we can see the key icon is next to CustomerID, PK_Customers and PK_Customers(Clustered) from Columns folder, Keys folder and Indexes folders respectively.
Notes: I use the sample database from Microsoft SQL Server 2022 Essential Training With Adam Wilbert.
Comments
Post a Comment