Correct test answer?

Choose the correct syntax to insert rows into dim_country table

Which ones are correct, i kept on trying but test always shows wrong. Any ideas?

The 3rd one is correct. (I'm not sure about the 5th one, since that is not T-SQL (SQL Server) but some other rdbms.)

Hi,

thanks for your answer but if I pick only third one and press submit it says incorrect.

The first one already checked looked correct. Add the 3rd one to that. And likely the one after the last one selected.

So, overall: 3rd, 6th and 8th would be my best guess.

nope, sadly

Assuming this is PostGreSQL, then 5 is also a valid option, in addition to 3,6 and 8.

1, 2 and 4 are syntactically incorrect.

Hi again,

This is a PostGreSQL, yet the answer is still not valid.

I don't know what to tell you, except to install a PostGreSQL instance and try them out. Or simply try every answer combination until you get the "correct" answer. I'm not a PostGres expert, other than the ones I mentioned being invalid syntax.

#3 is valid syntax and should work for the example DDL posted, and #6 is also valid, unless there's a problem with the date formats in the VALUES clause.

2 Likes

thanks for trying, I really appreciate it.

Is a SERIAL column actually the same as people think of an IDENTITY column? In other words, while you can't insert into a classic IDENTITY column without jumping through a hoop or two, can you insert into a SERIAL column without jumping through such a hoop?

The example they give at the intersection pages 158/159 in the documentation looks like this and they explain it with the alternative.

CREATE TABLE tablename (
colname SERIAL
);
-- is equivalent to specifying:
CREATE SEQUENCE tablename_colname_seq AS integer;
CREATE TABLE tablename (
colname integer NOT NULL DEFAULT nextval('tablename_colname_seq')
);

The alternative is a sequence and there's absolutely NOTHING to prevent you from inserting into a column that has a default of "nextval" for a sequence. Of course, you could have a UNIQUE constraint on the column to prevent you from entering DUPLICATE values but there's nothing to prevent you from entering a value with a DEFAULT of a sequence "nextval".

Since they're saying the two are identical, I'm thinking you can enter values into a column designated as a SERIAL.

I don't have Postgres to try it with, either.

1 Like

soo, which answers do you think should correct?

I think we've given enough advice.

Have you tried any of these examples on a PostGreSQL instance? It's free to install and use. I've already made this suggestion.

We don't have the test in front of us, and I assume you're taking this test in order to get some certification. Actually using the product will teach you more about it that any test will.

1 Like

Heh... you're the one that has to have Postgres loaded. And it looks like the "test" give you instant feedback. Spend a minute and try the bloody code! :wink:

1 Like

I tried it and it seems indeed confusing as certain codes work but then i mark it test shows incorrect...

So... do what I would do... Contact the people that provide the test and ask them! Not all people that create tests and answers are actually correct.

1 Like

To insert rows into the dim_country table, you can use the following syntax:

  1. Inserting a single row:

sqlCopy code

INSERT INTO dim_country (column1, column2, column3)
VALUES (value1, value2, value3);

Replace column1, column2, and column3 with the actual column names in the dim_country table, and value1, value2, and value3 with the corresponding values you want to insert for each column.

  1. Inserting multiple rows in a single statement:

sqlCopy code

INSERT INTO dim_country (column1, column2, column3)
VALUES (value1, value2, value3),
       (value4, value5, value6),
       (value7, value8, value9);

In this syntax, you can provide multiple sets of values separated by commas within the VALUES clause. Each set corresponds to a row that will be inserted into the dim_country table.

Remember to replace column1, column2, and column3 with the actual column names, and value1, value2, value3, etc., with the desired values for each row.

Ensure that the number of columns and the order of the values match the structure of the dim_country table.

Note: Make sure you have the necessary permissions to insert data into the dim_country table.

I know it's "late" but for the ones who struggled like me:
The answer is:

3, 5, 6, 7, 9.

I tried each one.

If you want to try yourself, there is the code and all answers as a text:

CREATE TABLE dim_country (
country_id SERIAL NOT NULL,
country_name TEXT NOT NULL,
last_update TIMESTAMP NOT NULL DEFAULT NOW(),
CONSTRAINT Country_pk PRIMARY KEY (country_id)
);

INSERT IN dim_country (country_name) VALUES ('South Sudan'), ('North Makedonia');

INSERT INTO dim_country (country_name) VALUES ('South Sudan'),
('North Makedonia');

INSERT INTO dim_country (country_name) ROWS ('South Sudan'),
('North Makedonia');

INSERT INTO dim_country (country_name) VALUES ('South Sudan'),
('North Makedonia')
RETURNING Country_id;

INSERT INTO dim_country (country_name, last_update) VALUES ('South Sudan', '2020-01-01 17:00:00'), ('North Makedonia', '2020-01-01 17:00:00');

INSERT INTO dim_country
VALUES (11, 'South Sudan', '2020-01-01 17:00:00'), (12, 'North Makedonia', '2020-01-01 17:00:00');

INSERT INTO dim_country
VALUES ('South Sudan', '2020-01-01 17:00:00'), ('North Makedonia', '2020-01-01 17:00:00');

INSERT INTO dim_country
VALUES (11, 'South Sudan'),
(12, 'North Makedonia');

after creating a table and trying the queries, don't forget to rollback when it's necessary.

best wishes!!