0

I have this problem when using Microsoft Access on SQL view I always get syntax error but when I remove the numeric line it runs ok !!

How can I fix that?

create table student
    (ID varchar (5),
    name varchar (20) not null,
    dept_name varchar (20),
    tot_cred numeric (3,0) default 0,
    primary key (ID))

This is the error I get

enter image description here

Andre
  • 26,751
  • 7
  • 36
  • 80

2 Answers2

1

According to Access' documentation, Number is to be used, not Numeric.

The reason that it cannot switch out of SQL is that it tries to fit the SQL you wrote into the Wizard, but he cannot match numeric(3,0) to a Datatype. the easiest way to solve that issue is to remove the field, and create it against from the wizard by using the Datatype dropdown.

So your SQL should look a bit like this :

create table student
(ID varchar (5),
name varchar (20) not null,
dept_name varchar (20),
tot_cred number default 0,
primary key (ID))

I'm not certain how you add the default clause, but according to their syntax, it cant, be done in the CREATE TABLE statement. I also believe it depends on your version of Access (hopefully 2000+ because otherwise you'll have to use workarounds).

Once again, the easiest way to do it is to use the Wizard and look at the result in the SQL View.

Julien Blanchard
  • 825
  • 5
  • 18
0

You cannot use the DEFAULT clause with a CREATE TABLE statement in Access SQL, at least not when running it from the query editor / SQL view.

You need to either run the SQL command via an ADO connection:
SQL SET DEFAULT not working in MS Access

or set the Access option under Query Design to ANSI 92 compatible:
SQL to add column with default value

See this answer for more details.

Community
  • 1
  • 1
Andre
  • 26,751
  • 7
  • 36
  • 80