skip to Main Content

I wanted to execute the following statement to create a table for storing various details .Here name of movies will store there “Ratings in integer value” Please help me solve this issue

CREATE TABLE users (
    id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    username VARCHAR(50) NOT NULL UNIQUE,
    password VARCHAR(255) NOT NULL,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    website VARCHAR,
    aboutyou VARCHAR,
    gender VARCHAR(50) NOT NULL,
    avengers INT NOT NULL,
    inception INT NOT NULL,
    godfather INT NOT NULL,
    mrrobot INT NOT NULL,
    xfiles INT NOT NULL,
    friends INT NOT NULL
);

I get error from phpmyadmin as:

MySQL said: Documentation

#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘aboutyou VARCHAR,
gender VARCHAR(50) NOT NULL,
avengers INT NOT’ at line 6

2

Answers


  1. Give them length as you did with gender and it will work.

     website VARCHAR(50),
     aboutyou VARCHAR(50),
    
     gender VARCHAR(50) NOT NULL,
    
    Login or Signup to reply.
  2. Well, I think if you give the query a closer look, you will understand it yourself!

    I guess that the error is due to the fact that you do not provide the VARIABLE for the length of the string. You specify only that you want to use VARCHAR as a data type for the columns website and aboutyou. But the correct form is VARCHAR(n), where n the number of characters you want your string to be. I tried to implement it myself, and when I gave a number enclosed in parentheses, it worked perfectly.

    An example, try:

    CREATE TABLE users (
        id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
        username VARCHAR(50) NOT NULL UNIQUE,
        password VARCHAR(255) NOT NULL,
        created_at VARCHAR(5),
        website VARCHAR(55),
        about_you VARCHAR(255),
        gender VARCHAR(50) NOT NULL,
        avengers INT NOT NULL,
        inception INT NOT NULL,
        godfather INT NOT NULL,
        mrrobot INT NOT NULL,
        xfiles INT NOT NULL,
        friends INT NOT NULL
    );
    

    I hope that helps and answers your question.
    Good luck with your project!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search