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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 6, 2012, 6:50 PM EST
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.VulpesRank #55 · 29.2K reputationPosted Mar 6, 2012, 4:18 AM EST
SenthilkumarRank #387 · 6.5K reputationPosted Mar 6, 2012, 7:11 PM EST
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.
fahad sheikhji50 reputationPosted Mar 6, 2012, 9:07 PM EST