Jim
Jim

Reputation: 851

What's the error in my MySQL statement?

The following SQL statement has a syntax error according to phpMyAdmin, but I can't spot what it is. Any ideas?

CREATE TABLE allocations(
`student_uid` INT unsigned NOT NULL DEFAULT 0,
`active` INT unsigned NOT NULL DEFAULT 1,
`name` VARCHAR( 255 ) NOT NULL DEFAULT '',
`internal_id` VARCHAR( 255 ) DEFAULT '',
`tutor_uid` INT NOT NULL DEFAULT 0,
`allocater_uid` INT unsigned NOT NULL DEFAULT 0,
`time_created` INT NOT NULL DEFAULT 0,
`remote_time` FLOAT NOT NULL DEFAULT 0,
`next_lesson` VARCHAR NOT NULL DEFAULT -1,
PRIMARY KEY ( student_uid )
);

Upvotes: 0

Views: 300

Answers (4)

garyj
garyj

Reputation: 1432

next_lesson` VARCHAR NOT NULL DEFAULT -1,

should be changed to

`next_lesson` VARCHAR(255) NOT NULL DEFAULT -1,

Upvotes: 0

DigitalRoss
DigitalRoss

Reputation: 146053

Your last VARCHAR has no length.

Upvotes: 1

Abdullah Jibaly
Abdullah Jibaly

Reputation: 54790

2 things I can think of:

  1. I don't think you can set a varchar not null with an empty default, mysql might consider an empty string the same as null.

  2. Set varchar fields to a string not a number, so:

    next_lesson VARCHAR NOT NULL DEFAULT '-1',

Upvotes: 0

Kyle Wild
Kyle Wild

Reputation: 8915

The VARCHAR type requires a size (and it's smart to use quotes around the value), so try replacing

`next_lesson` VARCHAR NOT NULL DEFAULT -1,

with

`next_lesson` VARCHAR(255) NOT NULL DEFAULT '-1',

Upvotes: 6

Related Questions