Solved

Create Table thru SQL with Auto_Increment

Posted on 2002-03-13
13
933 Views
Last Modified: 2013-12-24
I'm having difficulty with my create table code.. any ideas on whats wrong?

<cfquery name="Addtable" datasource="#application.db#">
  create table tbl_UserLinks
  (
       link_ID_PK INT NOT NULL default 0 auto_increment,
     address char(150),
     sent_by char(20),
     primary key (link_ID_PK)
  )
</cfquery>
0
Comment
Question by:M_Corkish
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 5

Expert Comment

by:Yog
ID: 6861041
I guess

<cfquery name="Addtable" datasource="#application.db#">
 create table tbl_UserLinks
 (
      link_ID_PK INT NOT NULL default 0 auto_increment PRIMARY KEY,
    address char(150),
    sent_by char(20)
 )
</cfquery>
0
 
LVL 1

Expert Comment

by:techy6
ID: 6861065
What DB are you using?  I think there's a problem with your last line - the primary key statement.  If I was doing this on Oracle, I'd do it like this:

create table tbl_UserLinks
 (
    link_ID_PK number(8) NOT NULL primary key,
    address varchar2(150),
    sent_by varchar2(20)
 )

and use a sequence in order to auto-increment your key values.

0
 

Author Comment

by:M_Corkish
ID: 6861165
I'm using ms-sql, but also testing it locally sometimes on a different db (local access db)

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 6

Expert Comment

by:reitzen
ID: 6861181
For SQL Server, use the following:

CREATE TABLE
  tbl_UserLinks
  (
     link_ID INT IDENTITY (1,1) NOT NULL,
  ,  address char(150) NOT NULL
  ,  sent_by char(20) NOT NULL
  )
  ON PRIMARY
0
 
LVL 11

Expert Comment

by:jimmy282
ID: 6861198
here is correct SQL for ms-sql

CREATE TABLE [dbo].[SUBSCRIBERS] (
     [id] [int] IDENTITY (1, 1) NOT NULL ,
     [Name] [varchar] (50) NULL ,
     [Email] [varchar] (50) NULL
) ON [PRIMARY]


ALTER TABLE [dbo].[SUBSCRIBERS] WITH NOCHECK ADD
     CONSTRAINT [PK_SUBSCRIBERS] PRIMARY KEY  CLUSTERED
     (
          [id]
     )  ON [PRIMARY]



Change your table names and column names.

Jimmy
0
 

Author Comment

by:M_Corkish
ID: 6861205
neither ideas seemed to work.  I don't know whats wrong..
0
 
LVL 6

Expert Comment

by:reitzen
ID: 6861269
I got this to work on my SQL Server 7.0.  Run it using Query Analyzer:

CREATE TABLE [dbo].[tbl_UserLinks] (
     [link_ID] [int] IDENTITY (1, 1) NOT NULL ,
     [address] [char] (150) NOT NULL ,
     [sent_by] [char] (20) NOT NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[tbl_UserLinks] WITH NOCHECK ADD
     CONSTRAINT [PK_tbl_UserLinks] PRIMARY KEY  CLUSTERED
     (
          [link_ID]
     )  ON [PRIMARY]
GO
0
 
LVL 11

Expert Comment

by:jimmy282
ID: 6861281
what error?
0
 

Author Comment

by:M_Corkish
ID: 6861327
this is the error i get on the local ms access DB:
=============

37000 (Syntax error or access violation)

[Microsoft][ODBC Microsoft Access Driver] Syntax error in CREATE TABLE statement.

0
 
LVL 11

Accepted Solution

by:
jimmy282 earned 75 total points
ID: 6861464
this is for Access


create table tbl_UserLinks
 (
      link_ID_PK    AUTOINCREMENT NOT NULL ,
    address char(150),
    sent_by char(20),
PRIMARY KEY (link_ID_PK)
 )



Jimmy
0
 

Author Comment

by:M_Corkish
ID: 6863863
Jimmy, that did the trick!  so what exactly is going on there.. is it just the auto_increment becomes autoincrement that was throwing it?

cheers everyone.

0
 
LVL 11

Expert Comment

by:jimmy282
ID: 6863866
yes

auto_increment is used in MYSQL.
in MS-Sql its called Identity(1,1)
In Msaccess its autoincrement.

HTH
Jimmy
0
 

Author Comment

by:M_Corkish
ID: 6863949
so if my web server uses ms-sql, but the database i put on their server is an access db (not a commerical site, so access is fine! 8) should i be using the ms-sql code, or the access code?

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Service "nameserver" appears to be down 4 624
AD LDS, AD FS, RODC, LDAP access for 3rd party vendors? 5 136
New OSQA server has a ton of fake users 4 71
Link failure 16 31
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question