Question

CREATE TABLE Message(
    MessageID int unsigned not null auto_increment primary key,
    naiveUserID int unsigned(7) NOT NULL,
    Title varchar(20),
    bodyOfText TEXT(2000)
);

I keep trying to run this simple create table blurb on a Mysql5 database and I keep getting the error:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
 corresponds to your MySQL server version for the right syntax to use near '(7) NOT NULL,
        Title varchar(20),
        bodyOfText TEXT(2000)
)' at line 3

I've googled the proper syntax from several different sites and can't make anything run! The maddening part is that when I use my teacher's code, which is very similar to this apart from some data types, it runs perfectly:

CREATE TABLE EMPL (
Eid int unsigned not null auto_increment primary key,
Name varchar(20),
title varchar(30),
salary int,
emailsuffix varchar(60)
);
Was it helpful?

Solution

It's because your syntax is indeed wrong: there's no int unsigned(7)type; try this:

CREATE TABLE Message(
    MessageID int unsigned not null auto_increment primary key,
    naiveUserID int(7) unsigned NOT NULL,
    Title varchar(20),
    bodyOfText TEXT(2000)
);

or:

CREATE TABLE Message(
    MessageID int unsigned not null auto_increment primary key,
    naiveUserID int unsigned NOT NULL,
    Title varchar(20),
    bodyOfText TEXT(2000)
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top