Auto Number Or Identity Seed On Oracle Database
Jul 23, 2005
Need help on the Auto Number or Identity Seed on the Oracle Database
I got an Access database that need to be converted to Oracle 9i.
Somehow the Trigger we created to simulate the "AUTO NUMBER" on Access
could not create the sequence number as soon as the value has been
inserted. The sequence number can only be created after we go to the
second line. Please see the trigger below.
Is there anyway we could create a trigger that could create the
sequence number as soon as we enter a value? It should be very
similar to the "Auto Number" on Access, or "Identity Seed" on SQL
Server.
----------------------------------------------------------
1. sequence SNP.SECTION_ID_SQ:
CREATE SEQUENCE SNP.SECTION_ID_SQ
START WITH 1
INCREMENT BY 1
NOMINVALUE
NOMAXVALUE
NOCYCLE
CACHE 20
NOORDER
/
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_ID
BEFORE INSERT
ON SNP.SNP001_SECTION
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW WHEN (new.section_id IS NULL)
BEGIN
SELECT section_id_sq.nextval
INTO :new.section_id
FROM dual;
END;
View 1 Replies
ADVERTISEMENT
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
Oct 8, 2007
Hi,
I have the following two tables:
Code:
create table RECORD
(
ID int not null,
Issue_descr varchar(256) not null,
Priority varchar(5) not null,
Status varchar(12) not null,
Date_add varchar(10) not null,
Date_due varchar(10) not null,
Date_complete varchar(10),
PName varchar(32),
primary key(ID),
foreign key(PName) references PROJECT(PName)
);
and
Code:
create table STEPS
(
ID int not null,
Num int not null,
Descr varchar(256),
Date_due varchar(10) not null,
Date_complete varchar(10),
Status varchar(12),
primary key(ID, Num),
foreign key(ID) references RECORD(ID)
);
I have set PK "ID" in table RECORD to auto identity(1,1). I have done the same for PK "num" in table STEPS.
However I am seeking this behavior in STEPS:
ID num
-- ----
19 1
19 2
19 3
20 1
20 2
21 1
but what I'm getting is PK num doesn't "reseed" or reset to 1 as "ID" changes. PK num just auto-increments regardless of ID. Is there a workaround?
Thanks.
View 2 Replies
View Related
Jul 20, 2005
I am migrating a web application I wrote from ASP to ASP.Net, and fromAccess to MS SQL server.In the Access version, I did not use the auto number for creatinginvoices and other documents, because I heard somewhere (perhapsincorrectly) that if the db was ever compacted or otherwise changed,it could change the values of the auto-numbers. Not a good thing.So I wrote a routine that, just before creating a new record, wouldlook for the highest value in the table and create the new record withthe next number.So my question is, am I safe in assuming that in MS SQL that I can seta starting number for the next, let's say, invoice and that newnumbers will be issued in sequence, and that these numbers will neverchange? What happens if an invoice is deleted? is the number goneforever? Just wondering how others deal with these issues...thanks.Larry- - - - - - - - - - - - - - - - - -"Forget it, Jake. It's Chinatown."
View 2 Replies
View Related
Jan 24, 2005
Hi ,,
How to write the Sql Query to return the next generated Identity from the Sql server database.
View 1 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
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
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
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
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
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
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
Jan 23, 2004
I have an MS SQL Server table with a Job Number field I need this field to start at a certain number then auto increment from there. Is there a way to do this programatically or within MSDE?
Thanks, Justin.
View 3 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 19, 2005
Ok,I just need to know how to get the last record inserted by the highestIDENTITY number. Even if the computer was rebooted and it was twoweeks ago. (Does not have to do with the session).Any help is appreciated.Thanks,Trint
View 2 Replies
View Related