What's wrong with this MS SQL statement?

  • CREATE TABLE asdfasdf234134 (id autoincrement,firstname varchar(155),lastname varchar(155),email varchar(155),CONSTRAINT id_pk PRIMARY KEY(id));

    CREATE TABLE asdfasdf234134_sales (id autoincrement,saletime varchar(155),name varchar(155),desc varchar(155),qty varchar(155),price varchar(155),CONSTRAINT id_pk PRIMARY KEY(id));

    It's fine with the first table creation, but not the second one. Why? the asdf.. is the username that the user inputs on the registration page. I understand that quantity and saletime should be different data types, I figured it would simplify the troubleshooting for now to make them all varchar.

    Gabriel

  • What error second one gives you?

    Put column name desc within square brakcets as it is reserved word.

    Is autoincrement a UDDT (user defined data type)?

    Don't use varchar for qty, price, etc. Use proper data types and length.

  • Here's the error:

    Microsoft JET Database Engine error '80040e14'

    Syntax error in field definition.

    I changed 'name' to 'fullname' - still getting same error.

  • I've taken autoincrement out. I was operating under the assumption that I had to add a primary key, I wasn't aware that a rowid was created by default as the primary key.

    Error still remains...

  • Are you using SQL Server or Access?

  • Access

  • Even in Access you can't use reserved words. You seem to be short cutting a lot or best practices here. Column names like ID. You should at the very least use the TableNameID as the name of the column.

    The problem in your second table is you are trying to name a column "desc", a reserved word. How about Description instead? The table creation is failing because it looks like a syntax error.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Are you really creating 2 new tables for every new user who registers on your system? Seems you aren't going to need many users before you hit the 32768 objects per database limit Access imposes!

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply