473,322 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to get the same index number for the primary key after i truncate and upload data

111 100+
Hii all,


I have a project where before i upload the data from 1st database to 2nd database, im truncating the 2nd database and then trying to upload...

In this process, wat i found was that: My records in the database are something like:

`tbl_workers` (`wo_worker_id_pk` bigint(11) unsigned NOT NULL auto_increment,
`wo_worker_code` varchar(6) NOT NULL default '',
`wo_worker_catagory` varchar(50) default NULL,

PRIMARY KEY (`wo_worker_id_pk`),
UNIQUE KEY `wo_worker_code_idx` (`wo_worker_code`)
)

Is there any method to get the same index number for the primary key after i truncate and upload the records to the database..

For ex:
before truncating i find my database started with: 3000(wo_worker_id_pk)

ive got about 600 records

Now after truncating n uploading i find them starting with other number (3600)(wo_worker_id_pk)


so it is auto incrementing ......
I want them to start with 3000....

is there any way ....


plz help..
thnx.
hepsi...
Jul 19 '07 #1
2 1893
mwasif
802 Expert 512MB
Use this query to decrement the current auto_increment field to previous level. I have used 600, use as appropriate.
Expand|Select|Wrap|Line Numbers
  1. UPDATE tbl_workers SET wo_worker_id_pk=wo_worker_id_pk-600;
This query will set the autoincrement index to start from 3600 (next record will be added with this auto_increment index). Make sure this is the correct value.
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE tbl_workers AUTO_INCREMENT=3600;
If you dont want to do this, simply truncate the table and run the following query and insert the records again.
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE tbl_workers AUTO_INCREMENT=3000;
Why you want the auto_increment value to 3000?
Jul 19 '07 #2
rhepsi
111 100+
Use this query to decrement the current auto_increment field to previous level. I have used 600, use as appropriate.
Expand|Select|Wrap|Line Numbers
  1. UPDATE tbl_workers SET wo_worker_id_pk=wo_worker_id_pk-600;
This query will set the autoincrement index to start from 3600 (next record will be added with this auto_increment index). Make sure this is the correct value.
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE tbl_workers AUTO_INCREMENT=3600;
If you dont want to do this, simply truncate the table and run the following query and insert the records again.
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE tbl_workers AUTO_INCREMENT=3000;
Why you want the auto_increment value to 3000?
hiii,

thnx...

it helped me...


regards
hepsi....
Jul 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: stef | last post by:
Hi, I have a range partitioned (one partition = one month) table. On this table I have a local unique index and a local domain index (Oracle Text) on a CLOB column. I'm running Oracle...
25
by: sql_server_2000_user | last post by:
Hi, I have a table with about 305 million rows, and a composite primary key that consists of an ascending int and an ascending varchar(18), which is typically of length 13. Even if all the keys...
6
by: christopher.secord | last post by:
Is there any advantage to doing this: ALTER TABLE testtable ADD CONSTRAINT PK_sysUser PRIMARY KEY NONCLUSTERED (UserID) WITH FILLFACTOR = 100, CONSTRAINT IX_sysUser UNIQUE NONCLUSTERED...
0
by: Megan | last post by:
Hi Everybody- I know that this is a really, really long post, but I wanted to try to give you as much background as possible. So here's a quick overview of the issues I'm asking for help with:...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
8
by: paii, Ron | last post by:
I have a table listing drawing numbers for jobs. It's primary key combines Job and numeric part of the drawing number. The structure allows the number part to repeat for each job. Job Dwg...
15
by: Sandham | last post by:
I have a series of tables in which the data can be refreshed from a file. Before refreshing the data, some of the tables are cleared using either TRUNCATE or DELETE. If TRUNCATE is used, any...
6
by: MGM | last post by:
Alright, so here's my issue. I have a bunch of .dbf files, about 40 or so by summer's end, I'd say. These dbf files somewhat differ from each other as far as number of columns and data is...
1
by: brian.j.parker | last post by:
One of the developers where I work found that some of his code would regularly cause index corruption in SQL Server 2000, post-sp4. @@version is 8.00.2050 and I can repeat this, so I can't...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.