mysql How to resolve Table must have at least one visible column issue while creating table? [closed]

wyyhbhjk  于 2022-12-22  发布在  Mysql
关注(0)|答案(1)|浏览(301)

Closed. This question is not reproducible or was caused by typos . It is not currently accepting answers.

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 days ago.
Improve this question

CREATE TABLE IF NOT EXISTS OLYMPIC_HISTORY;
(
id INT PRIMARY KEY,
name VARCHAR,
sex VARCHAR,
age VARCHAR,
height VARCHAR,
weight VARCHAR,
team VARCHAR,
noc VARCHAR,
games VARCHAR,
year INT,
season VARCHAR,
city VARCHAR,
sport VARCHAR,
event VARCHAR,
medal VARCHAR
);

Error:

A Table must have at least one visible column

How to fix the error and process too?

p8ekf7hl

p8ekf7hl1#

You have following issues:

  1. The semicolon in the first line must be removed
  2. The varchar columns require a maximum length, meaning you need to write for example varchar(100) instead of varchar only
  3. Year and Event should not be used as column name because they are SQL key words. This can cause further problems.
    Issue 1 and 2 must be solved, otherwise your create table command will fail.
    Issue 3 should be solved in order to avoid further difficulties.
    So a correct create table command will be something like this:
CREATE TABLE IF NOT EXISTS OLYMPIC_HISTORY
(
id INT PRIMARY KEY,
name VARCHAR(100),
sex VARCHAR(100),
age VARCHAR(3),
height VARCHAR(100),
weight VARCHAR(100),
team VARCHAR(100),
noc VARCHAR(100),
games VARCHAR(100),
eventYear INT,
season VARCHAR(100),
city VARCHAR(100),
sport VARCHAR(100),
olympicEvent VARCHAR(100),
medal VARCHAR(100)
);

Furthermore, it is strange you want almost all columns to be varchar. Columns like the age, height or weight are usually numeric. Mabye you should change this, too.

相关问题