Question: The developer before me created a database table called "Tools", it contains two fields, toolid - varchar(255) and toolname - varchar(100).

The toolid field is of type varchar, it's the primary key. There is data in the table. 

I would like to convert the varchar toolid field to be of type int, while perserving data w/ their keys, also I want this field to be auto increment. 

Currently the keys are numeric, such as 12 or 22 or 3. 

Whats the best way to do this?

Answer: 
If you want to just change the varchar field to an int field, of course it won't let you, because of the data-type mismatch, however, a very simple fix is:

Create a second table, which will contain all the fields from your primary.

```
CREATE TABLE `Tools2` SELECT * FROM `Tools`;

```

Empty out the data, as we need to change the toolname from varchar to int and can't do this when it's full.

```
TRUNCATE TABLE `Tools2`;

```

Okay, let's change the field type.

```
ALTER TABLE `Tools2` CHANGE `toolname` `toolname` INT(11) NOT NULL;

```

Now let's re-insert the data from the original table.

```
INSERT INTO `Tools2` SELECT * FROM `Tools`;

```

Tools2 is now a correct version of Tools, so remove Tools.

```
DROP TABLE `Tools`;

```

Finally, rename Tools2 to Tools so you're good to go.

```
RENAME TABLE `Tools2` TO `Tools`;

```
It is set to a primary key, the only way around this would be: to use 

SQL Server and go up to the like Database tab go down to options or preferences or something: From there you can tell the database to update the primary key in all other tables and just use the GUI to change the data type. You have to make sure the option is selected first, or it won't allow you to save the changes.

Whatever table the primary key relates to's datatype will need to change too.

So if you alter the table tools, you will have to alter the table that it is linked to, should this be the case.

You may have to drop and re-create the table in which case you can easily accomplish this in whatever editor you are using
You could actually use the IDENTITY(1,1) function to create unique identifiers for each toolid.

If you want to keep the same toolID you would have to create a new table with the correct column restraints, populate the table by running an insert into statement in ascending order or something like that...