I want to maintain all columns in all tables in a database by unique id and ID should be in increasing order.
When I will add a column in any table of database, the column should uniquely identified by its id in whole database.
I want to maintain all columns in all tables in a database by unique id and ID should be in increasing order.
When I will add a column in any table of database, the column should uniquely identified by its id in whole database.
There is a T-SQL keyword IDENTITY
use this to auto-increment a column.
If you define a table it would look like this:
CREATE TABLE MyTabel
(
ID int IDENTITY(1,1) PRIMARY KEY,
SomeColumn varchar(100) NOT NULL,
AnotherColumn VARCHAR(100)
)
The first value of IDENTITY
defines it's initial value. The second value is the increment. So if you write something like IDENTITY(100, 10)
the inital ID (first ID of the first row you add) would be 100. The second 110, third 120,...
+++EDIT+++
CREATE TABLE MyTable
(
ID uniqueidentifier NEWID() PRIMARY KEY,
SomeColumn varchar(100) NOT NULL,
AnotherColumn VARCHAR(100)
)