Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

sql - how can I create second table in mysql? 1050 error

i'm creating second table in HEIDI SQL, but it doesn't work. it shows 1050 error: user1 aleady exists.

I aleady created user1 table and I try to create user2 table. However it doesn't

#2. TABLE

CREATE TABLE user1(
    user_id INT,
    name VARCHAR(20),
    email VARCHAR(30),
    age INT(3),
    rdata DATE
);

# TABLE 2

CREATE TABLE user2(
    user_id INT PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(20) NOT NULL,
    email VARCHAR(30) UNIQUE NOT NULL,
    age INT(3) DEFAULT 30,
    rdate TIMESTAMP
);
question from:https://stackoverflow.com/questions/65917141/how-can-i-create-second-table-in-mysql-1050-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can run this script, which will avoid this error "1050 error: user1 aleady exists.":

    CREATE TABLE IF NOT EXISTS `user1 ` (
      user_id INT,
      name VARCHAR(20),
      email VARCHAR(30),
      age INT(3),
      rdata DATE
    );

NB: your user1 table doesn't have a primary key and for the age column, it's advisable to store the date of birth because the age can be calculated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...