Print Page | Close Window

SQL Question

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=22691
Printed Date: 29 March 2026 at 6:28pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: SQL Question
Posted By: VBScript
Subject: SQL Question
Date Posted: 15 February 2007 at 11:37am
Does anyone know how to add a primary key field that is an auto-incrimenting integer using an SQL Query.

I want to add this primary key field to a table when it is being created.

If I was to do this in MS Access I would set the field to an AutoNumber.

If someone could help with a quey that is both MS Access and MS SQL compatible I would be greatful.


-------------
http://www.james-r.co.uk" rel="no follow - James
http://www.gotrillian.com/?4498-20" rel="no follow - Trillian - M



Replies:
Posted By: WebWiz-Bruce
Date Posted: 15 February 2007 at 2:16pm
Access:-

ALTER TABLE [tableName] ADD [fieldName] AUTOINCREMENT

SQL Server:-

ALTER TABLE [tableName] ADD [fieldName] [int] IDENTITY (1, 1) PRIMARY KEY  CLUSTERED  NOT NULL


-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net