0

I'm working on a group project and I'm trying to drop my database, but I'm receiving the same error, no matter how I try to manipulate what I wrote. Hopefully someone can help me understand where I went wrong.

For the

type VARCHAR NOT NULL,
description VARCHAR, 
image VARCHAR, 

I've tried adding in "DEFAULT NULL" and adding in numbers next to VARCHAR. I keep getting the same error message. I left it as what I put above because with my API, I don't want to restrict the amount of characters I'll be receiving when I call on it.

CREATE DATABASE recycleThis_db;
USE recycleThis_db;

CREATE TABLE materials (
    id INT(11) NOT NULL AUTO_INCREMENT,
    type VARCHAR NOT NULL,
        description VARCHAR, 
        image VARCHAR, 
    materialID INT(11) NOT NULL, 
    PRIMARY KEY (id)
);

I keep getting this error message:

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 'NOT NULL, description VARCHAR, image VARCHAR, materialID INT NOT NULL' at line 3

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Google *MySQL reserved words*, and see if you can use `type` as a column name without jumping through hoops. And just for clarity, you're not trying to **DROP** your database. Dropping a database means deleting it, and you're not trying to do so. You're attempting to create a table. – Ken White Jun 26 '19 at 16:04
  • `type` is a keyword in MySQL, but it's not a Reserved Word https://dev.mysql.com/doc/refman/8.0/en/keywords.html#keywords-8-0-detailed-T – spencer7593 Jun 26 '19 at 16:10

1 Answers1

0

I believe VARCHAR requires a length specifier e.g. VARCHAR(10) or VARCHAR(250)

CREATE TABLE `materials`
( `id`            INT(11) NOT NULL AUTO_INCREMENT
, `type`          VARCHAR(80) NOT NULL
, `description`   VARCHAR(255)
, ... 

Reference: https://dev.mysql.com/doc/refman/8.0/en/char.html

excerpt:

The CHAR and VARCHAR types are declared with a length that indicates the maximum number of characters you want to store. For example, CHAR(30) can hold up to 30 characters.

spencer7593
  • 106,611
  • 15
  • 112
  • 140