Database Reference
In-Depth Information
There are two ways to add this ID column to a table: using the alter table statement and dropping
and re-creating the table.
ALTER TABLE
Adding an identity key to a precreated column is based on an alter table statement. To try it, type the
following statement in the query pane, select it, and press Execute.
ALTER TABLE MySqlTable
ADD Id int IDENTITY(1,1)
This statement will add an Id column to the table. To see this newly added column, you need to
refresh the table by selecting it in Object Explorer, right-clicking, and choosing Refresh. Then expand the
Table node and the Columns node, and you will see the Id column added to the table, as shown in
Figure 3-9.
Figure 3-9. Looking at the newly added column to an existing table
So, now you have learned how to add a column to an already created column. The only problem
with this approach is that any column you add using ALTER is always added at the very end of the column
list, and there is no way you can move or switch its position in any way.
 
Search WWH ::




Custom Search