hi i want to give auto increment for this character
4MT08C5100 how to set for this in column datatype??what i have to selecte.i tried varchar but i cant make auto increment??
can any one suggest me??
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Mar 6, 2012, 11:50 PM
In SQL server, you can make Auto Identity column which column has data type int or bigint.
I prefer artificial primary keys,
i think Your requirements can also be implemented as unique index on a computed column.
example
try...
CREATE TABLE [dbo].[AutoIncrementTest](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Range] [varchar](50) NOT NULL,
[Descriptor] AS ([range]+ RIGHT('0000000' + CAST(Id AS VARCHAR(7)), 7)) PERSISTED,
CONSTRAINT [PK_AutoInc] PRIMARY KEY ([ID] ASC)
)
GO
CREATE UNIQUE INDEX [UK_AutoInc] ON [dbo].[AutoIncrementTest]
(
[Descriptor] ASC
)
insert into AutoIncrementTest (range) values('4MT08C')
insert into AutoIncrementTest (range) values('4MT08C')
insert into AutoIncrementTest (range) values('4MT08C')
select * from AutoIncrementTest
hope this help.fahad sheikhjiPosted Mar 7, 2012, 2:07 AM
SenthilkumarPosted Mar 7, 2012, 12:11 AM
We do not have any option to do auto increment for varchar. But if we have like that then it will be good. Its like albha numeric.
Usually it can be only do it for the integer columns
IDENTITY(1,1)
Where IDENTITY is key word and first arqument is starting number and next arqument is stepping parameter. When you (1,1) then it will start from 1 and it will increment by one for every insertion.
Still if you want to implement the auto number with char then it has to be implemented through the trigger.
VulpesPosted Mar 6, 2012, 9:18 AM