Naeem Dogar
Naeem Dogar

Reputation: 67

How to create a table in MySQL?

I have tried to develop a table in Mysql, I have tried to fulfil the requirements but can't seem to fix a specified error. The requirements are:

Table name: vehicles

reg_no: VARCHAR(8) NOT NULL,

category: ENUM('car', 'truck') NOT NULL DEFAULT 'car',

brand: VARCHAR(30) NULL DEFAULT '',

description: VARCHAR(256) NULL DEFAULT '',

photo: BLOB NULL,

daily_rate: DECIMAL(6,2) NOT NULL DEFAULT 9.99

I have attached screenshots about how I tried create this table, and have also attached a screenshot of the error.SQL SQLError

Upvotes: 1

Views: 3044

Answers (4)

Er. Nadim Shaikh
Er. Nadim Shaikh

Reputation: 1

//Simple initial stage Mysql table is created as follows...

create table studentdata(
     ID int,
     Name varchar(100),
     Marks int,
     Std varchar(10));

Upvotes: 0

Kevin Böhmer
Kevin Böhmer

Reputation: 456

Just tried it using sqlfiddle with the following code and it works.

create table vehicles (
reg_no VARCHAR(8) NOT NULL,
category ENUM('car', 'truck') NOT NULL DEFAULT 'car',
brand VARCHAR(30) NULL DEFAULT '',
description VARCHAR(256) NULL DEFAULT '',
photo BLOB NULL,
daily_rate DECIMAL(6,2) NOT NULL DEFAULT 9.99
);

I just took your description out of the question and edited it so it would fit the MySQL Syntax

Upvotes: 2

Shrikshel
Shrikshel

Reputation: 37

You should remove DEFAULT 'car'.

If an ENUM column is declared to permit NULL, the NULL value is a valid value for the column, and the default value is NULL. If an ENUM column is declared NOT NULL, its default value is the first element of the list of permitted values.

Source MySQL Doc

Upvotes: 0

Fabien Pittier
Fabien Pittier

Reputation: 98

In your screenshot "SQL" you've missed a comma between Car and Truck (In the "Length/Value" field)

Upvotes: 1

Related Questions