Learn SQL by Building a Student Database: Part 1 - Build a Student Database: Part 1

Hi there everyone, stuck here on the insert into - values and adding the names of the majors into my table - wondering if i messed something up along the way that is causing the issue or smth?

here is what I have so far
±---------±----------------------±----------±---------±-----------------------------------------+
| Column | Type | Collation | Nullable | Default |
±---------±----------------------±----------±---------±-----------------------------------------+
| major_id | integer | | not null | nextval(‘majors_major_id_seq’::regclass) |
| major | character varying(50) | | not null | |
±---------±----------------------±----------±---------±-----------------------------------------+
Indexes:
“majors_pkey” PRIMARY KEY, btree (major_id)
Referenced by:
TABLE “majors_courses” CONSTRAINT “majors_courses_major_id_fkey” FOREIGN KEY (major_id) REFERENCES majors(major_id)
TABLE “students” CONSTRAINT “students_major_id_fkey” FOREIGN KEY (major_id) REFERENCES majors(major_id)

postgres=> INSERT INTO majors(major) VALUES(‘Database Administration’);
INSERT 0 1
postgres=>

so as you can see above- this command isnt taking…if anyone could lend a hand, would really appreciate it! thanks alot.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

Challenge: Learn SQL by Building a Student Database: Part 1 - Build a Student Database: Part 1

Link to the challenge:

What does this select command show?

SELECT * from majors;

just a second, lets find out

here we are, below
±---------±------------------------+
| major_id | major |
±---------±------------------------+
| 1 | Database Administration |
| 2 | Database Administration |
| 3 | Database Administration |
| 4 | Database Administration |
±---------±------------------------+
(4 rows)

Okay so was that what you were expecting? 4 rows? All containing the same major?

No, the command from my friend the tutor on MCC says -
It only needs the name of a major. The ID will be added automatically. Add the first major from the courses.csv file into the majors table. It’s a VARCHAR , so make sure to put the value in single quotes.
see below for a partial list of the majors we are to input into the table…

major,course
Database Administration,Data Structures and Algorithms
Web Development,Web Programming
Database Administration,Database Systems

Can you please clarify your question? (I had thought that you were having a hard time inserting one row, but it seems not)

I just wasn’t sure where I was screwing up to get through the project is all, sorry if it was too vague-
I am getting the following error: Maybe this helps?
The “majors” table should have the correct row added

INSERT INTO majors(major) VALUES(‘Database Administration’); < This is the command that Code Road is asking for to get through to the next step.

Just was hoping you (or anyone else) could spot where the mistake is that is holding me up. Thanks again :slight_smile:

Well you now have 4 rows of the major that coderoad wanted so my guess is that your next step should be:

  • delete these rows and after that
  • try to reset the coderoad step and then
  • try to do the requested insert command after that. (But only do it once and hopefully this will trigger coderoad to move on)

I think that would make some sense…
DELETE ROW majors(major) VALUES (‘Database Administration’);

^ is this on the right track?

DELETE FROM majors;

This will delete all the rows added.

Tyty! Appreciate your time/energy

1 Like

±---------±------------------------+
| major_id | major |
±---------±------------------------+
| 6 | Database Administration |
±---------±------------------------+
(1 row)

So here is what we got - looks good from what I see?
The “majors” table should have the correct row added
^ Still getting the above error though :confused:

Ill hop in the discord server for FCC and see if I can track down some help…dont want to bog you down all evening with my silly probs!