Identity, Seed, Increment
Aug 25, 2005
Iam trying to add a column to an existing table that would be an "identifier". I called it "ReadingNumber" and selected Identity "Yes" and "Identity increment" as 1.
When I add it, it just gives the rows random numbers instead of by the order they were inserted into the database by.....is there a way to autonumber the columns correctly? I have a COLUMN called Date and also one called Time that have the date and Time, but the format is char.
Would I have to convert the date time columns into something SQL understands, sort them ASC or DESC and then do the Identity column add?
Thanks for any help
Edited
View 15 Replies
ADVERTISEMENT
Oct 1, 1998
I have created a table that generates a sequential id and a
stored procedure that will return that id. The trouble is
no matter what I set the Seed or Increment values to, the
id will always start with #1 and increment by 1.
My table is BILLING_TIME_ID
Identity field BT_GEN_ID
(SEED 200, INCREMENT 1)
The sp is as follows:
CREATE PROCEDURE BT_NEXT_ID
AS
INSERT dbo.BILLING_TIME_ID DEFAULT VALUES
select count (*) from dbo.BILLING_TIME_ID
GO
I have double checked that Identity_Insert is set to off for
this table. (does this default to off unless it is set to on?) Since
there is only 1 field in the table, I don`t have any indexes set.
Thanks for your help!
Toni
View 1 Replies
View Related
Mar 16, 2004
Hi all,
I've been thrown a curve ball late in the game on an application I'm developing. Without getting into the specifics of the application I store a unique employee ID number for all person records in it. This ID is provided to us by the companies we're servicing. Up until this point in time we didn't have need of an externally visable ID other than the one provided to us. Now, a need for an internally generated (by our application) unique ID has been discovered. This number needs to be a minimum 5 digits (e.x. 10001, 10002, ....). I could achieve this nicely by seeding an identity column at 10000 with an increment of 1. However, I've alredy made different settings for this and there are records in the db with the old ones.
My question is: If I initially set the seed / increment at 1/1 can I change this after the fact without causing data integrity problems. Will all subsequent insertions into this table just start at the new values?
Or, ideally I'd like to create a new column seperate from the PK Identity column already in place that serves the same function, incrementing a 5 digit number by 1 for each new record. Seems that you're only allowed one identity column per table though. Is there another way to achieve get the same result as identity?
Thanks!
View 4 Replies
View Related
Sep 5, 2007
Dear Sir,
the following code is copied from the SQL Server Help Example.
CREATE TABLE MyCustomers2 (CustID INTEGER IDENTITY (100,1) PRIMARY KEY, CompanyName NvarChar (50))
INSERT INTO MyCustomers2 (CompanyName) VALUES ('A. Datum Corporation')
ALTER TABLE MyCustomers2 ALTER COLUMN CustId IDENTITY (200, 2)
It gives the following error.
Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'IDENTITY'
Can U please guide me abt the error.
with regards,
wilfi
View 5 Replies
View Related
Dec 11, 2007
Hello,
I Have a table that needs to have 2 unique number.
detail_id and detail_print_id.
detail_id is already an IDENTITY.
both fields need to be different, because when importing, it imports the same data into a table twice, with only a slight data change (and id is not one of the changes).
So I thought i could do the following:
detail_id INT NOT NULL IDENTITY(1,2),
detail_print_id INT NOT NULL IDENTITY(2,2),
--blah blah
that way, the detail_id will always be odd, and the detail_print_id will always be even. however SQL Server 2005 only allows 1 identity per table, and both these fields need to be auto generated when the field is inserted, so as to prevent double data.
is there anyway I can create a int column to auto increment, without the column being an IDENTITY??
also, I would prefer to not have to create a second table with a single column just for this work.
Thanks,
Justin
View 5 Replies
View Related
Sep 10, 2007
I'm still in the development stage and am frequently deleting all data from all tables and then filling those tables anew. However, the increment seed for identifying fields doesn't reset to 1 (or 0--not sure which). While not important for operation of the database, I would prefer that the field identifiers start with 1 when I am ready to release the database for operation. Is there a way to do this?
I can generate scripts to rebuild the database structure to do this, but scripts aren't generated for database diagrams and the graphical representation of the table structure is very useful.
View 4 Replies
View Related
Dec 11, 2007
Hi guys,Please is it possible in SQL SERVER any version (Prefferably 2005) to set my Identity seed to the current year so that when we are in 2008 it continues from 2008 ?
Best Regards
View 2 Replies
View Related
Nov 5, 2003
Hello-
I am auto generating an id when a record is input into my database.
I know how to set the id field to create an identity seed for each new entry with an increment of 1.
Is there anyway to add characters to begining of this identity seed. Can it only be an integer.
For example I would like my id field to be in the following format:
NCID - 1
NCID - 2
.
.
.
.
Can anyone show me how to do this if possible?
Thanks
View 2 Replies
View Related
Nov 9, 2000
I have a table with an identity seed in it. I need to go back and get some history that wasn't loaded into it. I would then like to resequence the identity column. Is this possible? Can I use the dbcc checkident? or will this just start any future inserts with the number I specify. I would like to reseed the whole file when I'm done starting with 1 and going forward is this possible with this command.
View 2 Replies
View Related
Oct 12, 2000
Is there a way to drop the seed or sequence and recreate it? Thank you very much.
View 2 Replies
View Related
Sep 17, 1999
How can i reset the identity seed of a counter field to 1 after deleting
records from a table. Even though the identity seed displays 1 in the design
mode, when i add another record the counter field is incremented to the next
number from the last deleted record.
thanks
Todd Minifie
View 3 Replies
View Related
Sep 15, 2006
hello there
Just a quick question. (sql 2000)
Can you have and auto increment identity seed for a table that always ends with say a predefined Letter?
i.e.
1a , 2a, 3a, 4a, 5a, etc...
View 2 Replies
View Related
Jul 20, 2005
Can I change the value of a column's identity seed programmatically? Ifso, how?Thanks in advance.
View 2 Replies
View Related
Jan 9, 2004
Because of testing and deletion, my table of user groups starts at 15 or so. Now I want to insert a group for administrators but I would like to have the groupID be 1. I tried to turn off the identity seed property and insert it manually but that didn't work.
Is there any way to do this?
Thanks, Dave
View 3 Replies
View Related
Aug 26, 2005
Hello,
Can I reset the IDENTITY seed of a Table column without delete/drop the table?
I want to delete all the table rows, restore de seed, and restore a
backup made on a XML (using SET IDENTITY_INSERT Table ON)
I cant drop the table due to acount restricctions.
regards,
Edu
View 3 Replies
View Related
Jan 27, 2003
Hi,
I have a table which has a field called x which is set to identity with seed 1 and incerement 1.
Currently the table has 100 records so the last value of x is 100.
I would like to adavnce the seed number to be 1000, so that the next insert into the table will be 1001...
This is possible to do through the Enterprise manager, but I would like a script to do it.
Does anyone know where such a script exists?
What I actually need is a script that creates a CREATE TABLE Statement for the table (including all info - columns,indexes etc...).
thanks
Moshe
View 3 Replies
View Related
Jun 1, 1999
I would like to set the identity seed to a different value. How do I do that? Please help!
Sam
View 3 Replies
View Related
Apr 4, 2008
Hi ..
I have an issue here. I create a DB and some tables through a script in SQL Server. I have lot of tables in DB and quite a lot have identity columns with seed set to 1 and increment set to 1. The scripts executed fine and all the tables created. Now when I do the first insert records into the tables the identity column associated starts with 0 even though the seed is set at 1. Its the case with all the tables where the identity column are set. The first records into all these tables starts with 0 for all the identity columns.
I could'nt figure out what is causing this issue ..
Any fix for the issue ..
thanx in advance
View 1 Replies
View Related
Apr 4, 2008
Hi ..
I have an issue here. I create a DB and some tables through a script in SQL Server. I have lot of tables in DB and quite a lot have identity columns with seed set to 1 and increment set to 1. The scripts executed fine and all the tables created. Now when I do the first insert records into the tables the identity column associated starts with 0 even though the seed is set at 1. Its the case with all the tables where the identity column are set. The first records into all these tables starts with 0 for all the identity columns.
I could'nt figure out what is causing this issue ..
Any fix for the issue ..
thanx
View 2 Replies
View Related
May 15, 2006
My client has a need for the auto identity field to be 6 digits in length starting with the number 001000. They want the leading 0's preserved since this will be a casenumber. Even if I set the identity seed to 001000 it gets rid of the leading 0's. How can I get it to keep those?
View 1 Replies
View Related
Feb 16, 2004
I have a test database that is being moved to the production server. Currently in one of the tables I have an identity seed for each record. Is there a way to reset it back to zero. I have deleted all my records but it still doesnt work, and I dont want to create a new table.
Thanks
View 5 Replies
View Related
Mar 22, 1999
I'm trying to have an identity column seed value specified with a local variable value as follows, however it
doesn't allow me to do it (Says cannot use a variable name for a seed value).
Any ideas or suggestions?
DECLARE @idvalue int
SELECT @idvalue = max(accountid) + 1
FROM account
CREATE TABLE accounttemp
(Accountid int IDENTITY(@idvalue,1),
name char(10),
address char(10))
View 1 Replies
View Related
Aug 8, 2007
Sever: sql 2000
Replication: Merge
Issue:
I am having an issue with my audit table, This table is filled by Triggers on various tables through the database. All triggers are defied with "not for replication"
I have allocated 500k ranges, with 80% threshold to the publisher and subscriber databases for this table. The table only holds 225,000 records.
From time to time I get the following error "The identity range managed by replication is full and must be updated by a replication agent. The INSERT conflict occurred in database 'PublicationName', table 'AuditHistory', column 'AuditID'. Sp_adjustpublisheridentityrange can be called to get a new identity range."
When I looked into the issue yesterday I noticed that the identity range being used by replication was 334300001 -> 334799999, however the maximum value in the table was 334300096, meaning that only 95 records were inserted, which means it is no where near the 80% threshold.
Somehow the identity seed on the AuditHistory table had been changed to 334800104, which is outside the allowable range.
My question is what could cause the identity seed to get set to such a high number??
any thoughts would be great!
View 2 Replies
View Related
Feb 16, 2004
I'm using a stored procedure to create a table in sql 2000. One of the columns is an identity column. I need to set the seed to a max(number) from a column in another table, this column is not an identity column and can't be changed into one. I've been trying to set the seed by passing a variable. I continue to get errors so either I've got the syntax wrong or it's not possible to set the seed via a variable. Any words of wisdom would be appreciated.
View 5 Replies
View Related
May 9, 2008
Hi,
I've just recently learned that being an identity seed-column doesn't guarantee that you will always get unique values. It can double up and cause a violation of PK. If so, is there a work around this that doesn't involve a REINDEX? Cause if im home and my client suddenly experiences this in the middle of a busy day, that would be a total disaster. Any ideas on how i can avoid this or a workaround maybe? Thanks!
View 3 Replies
View Related
Aug 10, 2001
I am attempting to import data from a Lotus Notes database using DTS. The SQL table I am importing to has an identifying auto-number. I can't insert directly into it because the SQL server should, however I get an error if I ignore it in the DTS package. Is there any way to get around this?
View 4 Replies
View Related
Jul 23, 2005
Need help on the Auto Number or Identity Seed on the Oracle DatabaseI got an Access database that need to be converted to Oracle 9i.Somehow the Trigger we created to simulate the "AUTO NUMBER" on Accesscould not create the sequence number as soon as the value has beeninserted. The sequence number can only be created after we go to thesecond line. Please see the trigger below.Is there anyway we could create a trigger that could create thesequence number as soon as we enter a value? It should be verysimilar to the "Auto Number" on Access, or "Identity Seed" on SQLServer.----------------------------------------------------------1. sequence SNP.SECTION_ID_SQ:CREATE SEQUENCE SNP.SECTION_ID_SQSTART WITH 1INCREMENT BY 1NOMINVALUENOMAXVALUENOCYCLECACHE 20NOORDER/GRANT SELECT ON SNP.SECTION_ID_SQ TO "PUBLIC"/2. Trigger SNP.SNP001_T_I_GET_NEXT_SECTION_ID:CREATE OR REPLACE TRIGGER SNP.SNP001_T_I_GET_NEXT_SECTION_IDBEFORE INSERTON SNP.SNP001_SECTIONREFERENCING OLD AS OLD NEW AS NEWFOR EACH ROW WHEN (new.section_id IS NULL)BEGINSELECT section_id_sq.nextvalINTO :new.section_idFROM dual;END;
View 1 Replies
View Related
Aug 9, 2007
I have a set of staging tables that need to be used to update a hierarchy of tables with foreign keys between them, and identity columns for the primary keys. One way I'm thinking of doing this is to reset the identity seed on the target tables based on the number of rows I have in the staging tables, then to update the staging tables keys to match the vacated range of identity values. I'd insert them with SET IDENTITY_INSERT ON.
The question is: can this be done atomically? It seems that DBCC CHECKIDENT will return the current identity value, but can only change the seed to an absolute value. That would require that I get the current value, add "n" to it, then set the seed value. This would seem to be non-atomic, in that a new row could be inserted between the time I find the "current" value and the time I set the new value.
Does anyone know of a way to pre-allocate a block of identity values atomically? This has to be done in a live OLTB database.
View 4 Replies
View Related
Jan 9, 2015
We just switched from Sql server 2008R2 to Sql server 2012.I am facing one problem with identity Columns "When ever i restarts my sql server,the seed value for each identity column is increased by 1000 (For int identity column it is 1000 and for big int it is 10000).
"For Example if seed value of any table was 3 then after restarting sql server will be 1003 if i again restart sql server it will be 2003 and so on."
After searching on google i found that it is a new feature (don't know what is use of it) in sql server 2012 and having only two solution if you want old identity concept
1. Use sequence object -
a) I am using same database in sql server 2008 and 2012 both so can't use sequence in 2008.
b) if i go with sequence then need not change save procedure for each table,which is bulky task for us.
2. Use Trace Flag 272 (-T272)
I can go with this solution because there is need not do any changes in my application.Some one suggested me that add -T272 in startup parameter,after this sql server identity column will work normal as previous version.I did the same but it is not working.
I don't want to do any changes in my database structure.
how to use this -T272 or why it is not working.
I don't want to use this new identity feature how to suppress it. Why -T272 is not working.
View 4 Replies
View Related
Aug 22, 2000
Hello!
I is true that SQL-Server use lower values than last integer value (in auto incremet field). Is there option that i could prevent that. So the Server would always put + 1 for the auto increment value.
Thanks
Juissi
View 2 Replies
View Related
Oct 13, 2005
If delete all the records from a table that has an incremental identity. Is there a TSQL way of reset the first number on an insert back to be 1 again without going to the table taking it off then saving it the putting it back on again?
View 2 Replies
View Related
Apr 26, 2007
Hello, I need some help writing a script to generate Identity keys. I cannot use the row number generator because I would like to start the identity at a package level variable. Is this possible?
Thank you in advance
View 4 Replies
View Related
Sep 11, 2007
HiI have a Jobs Table: Job_ID,User_ID,Job_Info,...Job_ID is the Primary Key.I want to add [Job_ID_PerUser] so I wiil get:Job_ID Job_ID_PerUser User_ID1 1 A2 1 B3 1 C4 2 A5 3 A6 2 CThanks
View 4 Replies
View Related