Go to Top

More Alter Table SQL Statement Help

A while back I wrote a post on using temp tables in your code and I mentioned using Alter table statements to modify your temp tables on the fly. Today I’m going to talk about adding a primary key using code.

Click for a free quote.

SQL Server Hosting

Primary Keys are good in Temp Tables
They can help up speed your queries and should be added when needed. To add a AutoNumber key that is also a primary key you will need to use two statments, the first creating the field and the second making it a primary key using the following syntax:

Notice in the second statement Primary Key has a space between the words, and if you ever need a composite primary key just separate it by commas:


In the following example we use the table name tblTemp and the column name TempID as the primary key:

Here we used the column name as the index name, making it easier to remember later what is the primary key name when you need to search on the specific index.

I encourage you to continue using temp tables in your code and bringing improved functionality to your Access applications.

About Juan Soto

Juan Soto is a Senior Access Developer at IT Impact Inc. and a Microsoft Access MVP. He specializes in Access with SQL Server databases. His passion for Access has led him to helping a wide range of businesses in helping them establish a secure, stable and efficient environment with SQL Server. He's a frequent speaker at Access user groups nationwide and recently spoke at the Orange County SQL Saturday # 73. If you wish to have Juan speak at your next group meeting you can contact him here.

2 Responses to "More Alter Table SQL Statement Help"

  • Rafael
    August 5, 2017 - 7:07 am Reply

    Man, thank you
    I’m looking for that.

  • Carlos
    May 25, 2013 - 5:11 am Reply

    I got this website from my pal who told me regarding this web site and now this time I am browsing
    this website and reading very informative posts at this time.

Leave a Reply

Your email address will not be published. Required fields are marked *


Contact Us
close slider
  • This field is for validation purposes and should be left unchanged.