0

I am a beginner in SQL and I am currently stuck on something. So I tried to insert 3 rows in admin and it worked fine. Now I want to insert 3 rows of data in data_center however when running it I got an error "column "name" of relation "data_center" does not exist" can someone explain what's happening? Thanks in advance

CREATE TABLE admin
(
    username VARCHAR unique,
    PRIMARY KEY (username)
);

CREATE TABLE data_center
(
    name VARCHAR,
    username VARCHAR,
    capacity INT NOT NULL
        CHECK (capacity > 0 AND capacity < 20000),
    PRIMARY KEY (name),
    FOREIGN KEY (username) REFERENCES admin(username)
);

INSERT INTO admin (username)
VALUES ('Alan'), ('Bob'), ('Lea');
    
INSERT INTO data_center (name, username,capacity)
VALUES ('Alan Johnson'   'Alan'   '4000'),
       ('Bob Lane'   'Bob'   '2000'),
       ('Lea Larsson'   'Lea'   '6000');
3
  • Try to add Edward to the admin table too Commented Feb 27, 2022 at 19:28
  • I matched the FK values with the PK ones but I still have the same error Commented Feb 27, 2022 at 19:35
  • Please test your code after editing it but before posting it. Your posted code does not fail with the error you indicate. Commented Feb 28, 2022 at 2:10

1 Answer 1

2
  1. Values in record need to be comma separated.

  2. Capacity is integer value

    INSERT INTO data_center (name, username, capacity)
    VALUES  ('Alan Johnson', 'Alan', 4000),
            ('Lea Lane', 'Lea', 2000),
            ('Edward Larsson', 'Edward', 6000);
  1. Edward is not in admin table. Edward became Lea between edits.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.