Pgces 02

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 76

Set 1:

1) The table "custom" is defined below.

The "id" column and "introducer" column are of INTEGER type, and the "email" column is of

TEXT type.

id | email | introducer

----+-----------------+------------

2 | aaa@example.com | 1

3 | bbb@example.com | 2

4 | ccc@example.com | 2

Three SQL statements were executed in the following order: UPDATE custom SET email = ''

FROM custom c

WHERE custom.introducer = c.id;

UPDATE custom SET introducer = NULL

WHERE introducer NOT IN (SELECT id FROM custom);

DELETE FROM custom WHERE id = 2 OR introducer = 2;

Select the number of rows in the "custom" table after the execution.

Options are :

 4 rows

 3 rows

 2 rows

 0 rows

 1 row

Answer : 0 rows

SQL statements were executed in the following order. CREATE TABLE book (
id VARCHAR(21), title TEXT NOT NULL, price INT, UNIQUE (id), CHECK (price > 0)

);

INSERT INTO book VALUES ('4-12345-678-9', 'SQL book', 2300); --(1) INSERT INTO book (title,

price) VALUES ('PostgreSQL', 3000); --(2) UPDATE book SET id = '4-12345-678-9' WHERE id IS

NULL; --(3)

DELETE FROM book WHERE price < 0; --(4)

While executing, select the first location that generates an error.

Options are :

 No error is generated

 (3)

 (4)

 (2)

 (1)

Answer : (3)

Given the following two table definitions, select one SQL statement which will cause an error.

CREATE TABLE sample1 (id INTEGER, data TEXT);

CREATE TABLE sample2 (id INTEGER);

Options are :

 SELECT data FROM sample1 AS s1, sample2 AS s2 WHERE s1.id = 1 AND s2.id = 2;

 SELECT id, data FROM sample1 AS s1, sample2 AS s2 WHERE s1.id = s2.id;

 SELECT s1.id, s1.data FROM sample1 AS s1, sample2 AS s2 WHERE s1.id = s2.id;

 SELECT s1.id FROM sample1 AS s1;

 SELECT s1.id FROM sample1 s1;

Answer : SELECT id, data FROM sample1 AS s1, sample2 AS s2 WHERE s1.id = s2.id;

The table "t1" is defined below.


The column "id" for table "t1" is of INTEGER type.

id | name

----+------------

1 | mammoth

2 | tortoise

3 | coelacanth

The following SQL statements were executed. Select the correct statement about the execution

result.

BEGIN;

DECLARE c SCROLL CURSOR FOR SELECT name FROM t1 ORDER BY id;

MOVE FORWARD 2 FROM c;

FETCH FORWARD ALL FROM c;

COMMIT;

Options are :

 An error occurs part way through.

 The number of rows returned by the FETCH statement is 0.

 The number of rows returned by the FETCH statement is 3.

 The number of rows returned by the FETCH statement is 1.

 The number of rows returned by the FETCH statement is 2.

Answer : The number of rows returned by the FETCH statement is 1.

The table "foo" is defined as follows:

CREATE TABLE foo (bar TEXT);

Next, four SQL statements were executed in the following order. INSERT INTO foo VALUES

('bar'); -------- (1)

ALTER TABLE foo ADD COLUMN c1 TEXT; ---- (2)


ALTER TABLE foo ADD UNIQUE (c1); ------- (3)

ALTER TABLE foo DROP COLUMN bar; ------- (4)

Select the correct statement from those below.

Options are :

 An error occurs when executing the (1) SQL statement

 An error occurs when executing the (3) SQL statement

 No error is generated

 An error occurs when executing the (2) SQL statement.

 An error occurs when executing the (4) SQL statement

Answer : No error is generated

A set of tables are defined as follows:

t1

t2

How many rows are returned by executing the following SQL statement?

SELECT * FROM t1

WHERE EXISTS (SELECT name FROM t2 WHERE t1.id = t2.id);

Options are :

 5rows

 0 rows

 2rows

 4rows

 3rows

Answer : 2rows

A set of tables are defined as follows:

t1
t2

How many rows are returned by executing the following SQL statement?

SELECT * FROM t1 LEFT OUTER JOIN t2 USING (id);

Options are :

 3rows

 2 rows

 5rows

 4ows

 6rows

Answer : 4ows

SQL statements were executed in the following order: CREATE TABLE fmaster

(id INTEGER PRIMARY KEY, name TEXT);

CREATE TABLE ftrans

(id INTEGER REFERENCES fmaster (id), stat INTEGER, date DATE); INSERT INTO fmaster

VALUES (1, 'itemA');

INSERT INTO ftrans VALUES (1, 1, CURRENT_DATE);

Select the two SQL statements that will generate an error when executed next.

A. DROP TABLE ftrans;

B. INSERT INTO fmaster VALUES (1, 'itemB');

C. DELETE FROM fmaster;

D. UPDATE fmaster SET name = NULL;

E. INSERT INTO ftrans VALUES (1, 2, NULL);

Options are :

 a,b

 d,e
 c,d

 b,c

Answer : b,c

Select two incorrect statements regarding 'TRIGGER'.

A. When UPDATE is executed to the table, the specified function can be called.

B. When INSERT is executed to the table, the specified function can be called.

C. When SELECT is executed to the table, the specified function can be called.

D. A trigger can be set up to call a specified function before or after the event occurs.

E. A corresponding rule is automatically created when a trigger is created.

Options are :

 b,c

 c,e

 a,b

Answer : c,e

The table "score" is defined as follows:

gid | score

-----+-------

1 | 70

1 | 60

2 | 100

3 | 80

3 | 50

The following query was executed. Select the correct result value.

SELECT score FROM score ORDER BY gid DESC, score ASC LIMIT 1;
Options are :

 60

 80

 100

 70

 50

Answer : 50

The following table called company is defined as follows:

id | name

----+------------------

1 | Pgsql,inc.

2 | Postgres Co.,Ltd

3 | SQL Company.

Select the most appropriate psql command for generating a text file company.txt with the following

content on the client side.

1,Pgsql \,inc.

2,Postgres Co. \,Ltd

3,SQL Company

Options are :

 \copy company TO 'company.txt' WITH DELIMITER AS ',';

 \copy company TO 'company.txt' WITH ',';

 \copy company TO "company.txt"

 \copy company TO 'company.txt' DELIMITER ','

 \copy company TO company.txt CSV

Answer : \copy company TO 'company.txt' DELIMITER ','


Select two incorrect statements concerning the BOOLEAN type in PostgreSQL.

A. BOOLEAN is an alias of the INTEGER type in PostgreSQL.

B. BOOLEAN only takes either NULL, TRUE, or FALSE.

C. You can use the characters 't' or 'f' as a value for the BOOLEAN type.

D. You can use the TRUE or FALSE keywords as a value for the BOOLEAN type.

E. If the INTEGER value of '0' is inserted into a BOOLEAN column, it will be treated as FALSE

Options are :

 a,e

 b,c

 c,d

 a,b

Answer : a,e

Select one statement which will cause a syntax error.

Options are :

 SELECT * FROM (SELECT * FROM customer);

 SELECT (SELECT item FROM sale WHERE id = 1);

 SELECT * FROM sale WHERE cid = ANY (SELECT cid FROM customer);

 SELECT * FROM sale WHERE name IN (SELECT name FROM names);

 SELECT * FROM item WHERE cid IN (SELECT cid FROM customer);

Answer : SELECT * FROM (SELECT * FROM customer);

From the SQL commands below, select one that is generally classified as "DDL".

Options are :

 INSERT

 START TRANSACTION

 SELECT
 CREATE TABLE

 DELETE

Answer : CREATE TABLE

 Select one incorrect statement about schemas.

Options are :

 'SELECT current_schema();' returns the current schema.

 A schema is the name space for a database object.

 One user cannot own multiple schemas

 DROP SCHEMA' deletes a schema

 A schema is the name space for a database object.

Answer : One user cannot own multiple schemas

Select one incorrect statement concerning the following SQL statement. CREATE OR REPLACE

VIEW sales_view

AS SELECT * FROM sales_table ORDER BY sales_date DESC LIMIT 10;

Options are :

 You can confirm that the "sales_view" has been added by querying the view called "pg_views".

 C. When you 'SELECT' the "sales_view", it displays the first 10 records from the "sales_table" sorted by
the "sales_date" column in descending order

 Defines the view called "sales_view".

 Replaces "sales_view" if it already exists.

 Some errors occur when "SELECT * FROM sales_table" is executed after the view is defined

Answer : Some errors occur when "SELECT * FROM sales_table" is executed after the view is defined

A set of tables are defined as follows:

t1
t2

How many rows are returned by executing the following SQL statement?

SELECT * FROM t1 UNION ALL SELECT * FROM t2;

Options are :

 2 rows

 4 rows

 An error will occur.

 3 rows

 5 rows

Answer : 5 rows

A table is defined as follows:

CREATE TABLE t (id INT, val TEXT);

Select two correct statements from below about the function "get_head" defined below. CREATE

FUNCTION get_head(BOOLEAN)

RETURNS TEXT LANGUAGE sql CALLED ON NULL INPUT

AS 'SELECT val FROM t WHERE $1 OR id > 0 ORDER BY id LIMIT 1;';

A. This function is defined using PL/pgSQL.

B. There are cases where this function returns multiple lines.

C. When NULL is passed for the argument and the function is executed, NULL is returned.

D. Even if this function is passed the same parameter value and executed multiple times, the

returned values will not necessarily also be the same value.

E. If a function with the same name and with type BOOLEAN as the parameter is already

defined, an error occurs.

Options are :

 a,e
 a,b

 d,e

 c,d

Answer : d,e

Select two incorrect descriptions regarding the following SQL statements. CREATE TABLE cities (

name text,

population float );

CREATE TABLE capitals (

state char(2)

) INHERITS (cities);

A. Defines the tables called "cities" and "capitals".

B. "capitals" inherits "cities".

C. Searching "capitals" also searches rows in "cities".

D. The columns "name" and "population" are also defined in "capitals".

E. The second SQL statement results in an error, since the 'INHERITS' keyword is no longer

available.

Options are :

 a,b

 d,e

 c,e

 c,d

Answer : c,e

Select an incorrect statement regarding prepared statements, and 'PREPARE' / 'EXECUTE'

commands.

Options are :
 'PREPARE' can only specify 'SELECT' as a prepared statement.

 PREPARE' creates a plan for the prepared statement

 'DEALLOCATE' deallocates prepared statements.

 'PREPARE'/'EXECUTE' is mainly used to optimize performance

 'EXECUTE' executes the plan defined by 'PREPARE'.

Answer : 'PREPARE' can only specify 'SELECT' as a prepared statement.

Table t1 is defined as follows:

CREATE TABLE t1 (value VARCHAR(5));

A set of SQL statements were executed in the following order. Select the number of rows that

table "t1" has after execution.

BEGIN;

INSERT INTO t1 VALUES ('A');

SAVEPOINT sp;

INSERT INTO t1 VALUES ('B');

ROLLBACK TO sp;

INSERT INTO t1 VALUES ('C');

COMMIT;

Options are :

 4row

 5row

 3row

 0row

 1 row

Answer : 3row
The "sample" table consists of the following data:

How many rows are returned by executing the following SQL statement? SELECT i FROM sample

GROUP BY i HAVING count(*) = 2;

Options are :

 0 rows

 2 rows

 1 row

 4 rows

 3 rows

Answer : 2 rows

Select two correct statements about the command shown below. Note: $ is the command prompt.

$ vacuumdb -az

A. Recovers unused areas from all of the databases.

B. Collects statistical information related to the table content for all of the databases.

C. Processes the job equivalent of the VACUUM FULL command for all of the databases.

D. Processes the job equivalent of the VACUUM VERBOSE command for all of the databases.

E. The database can not be accessed until this command is finished.

Options are :

 a,b

 b,c

 d,e

 c,d

Answer : a,b

Select two suitable statements about postgresql.conf configuration.

A. A line that starts with ! (exclamation mark) is interpreted as a comment.


B. You can have different parameters for the same option to configure each database

differently.

C. The timing of when a change in any value is reflected is different depending on the

configuration parameter.

D. All options have no default values. Therefore, all of them must be set specifically and

thoroughly.

E. As a boolean value, any of the following can be used: TRUE, FALSE, ON, OFF, YES, NO, 1,

0.

Options are :

 c,e

 a,b

 d,e

 c,d

Answer : c,e

I would like to be able to save log entries as shown below. Select a correct configuration setting

from statements below.

LOG: connection received: host=[local] port=

LOG: connection authorized: user=postgres database=test

Options are :

 syslog = true

 log_min_level = log

 log_hostname = true

 log_connections = true

 log_authorization = true
Answer : log_connections = true

Select two commands used to check the syntax of the ALTER TABLE statement in psql.

A. \h ALTER TABLE

B. \h ALTER

C. \ ALTER TABLE

D. \ ALTER

E. HELP ALTER TABLE;

Options are :

 d,e

 c,d

 a,b

 b,c

Answer : a,b

A pg_hba.conf file is set up as follows.

local all all md5

host all all 127.0.0.1/32 md5

host all all 172.16.1.0/24 md5

When user foo connects to database bar from host IP address 172.16.1.2, I would like password

verification to not be performed.

Select one appropriate line for the new pg_hba.conf file.

Options are :

 Add "host foo bar 172.16.1.2/32 trust" to the first row.

 Add "host foo bar 172.16.1.2/32 trust" to the last row.

 The settings are fine as is.

 Add "host bar foo 172.16.1.2/32 trust" to the first row.


 Add "host bar foo 172.16.1.2/32 trust" to the last row

Answer : Add "host bar foo 172.16.1.2/32 trust" to the first row.

Select two statements that the command below DOES NOT do.

Note: $ is the command prompt.

$ pg_dump -b -F c b > d

A. Backs up the "b" database to the "c" file, and stores error messages to the "d" file.

B. Backs up the "b" database to the "d" file.

C. Backs up large objects.

D. Backs up the "c" database to the "d" file as the "c" user.

E. Creates a backup, which is restorable with the pg_restore command.

Options are :

 c,d

 a,d

 a,b

 b,c

Answer : a,d
Set-2

Select two incorrect statements about the Point-In-Time Recovery (PITR) from below.

A. This is a backup method integrating a physical backup and a transaction log (WAL).

B. It is necessary to stop the database server to perform a backup for the first time.

C. Updated data is continuously saved.

D. A restore can be performed to any arbitrary point in time since the starting point of PITR.

E. A backup can only be performed on a per-database basis.

Options are :

 a,b

 b,e

 d,e

 c,d

Answer : b,e

What does the following command do? Select the correct description from below. Note: "text=#" is

the command prompt for psql.

test=# ANALYZE foo;

Options are :

 Collects statistical information related to the content of the database foo

 The command does not generate an error; however, it does not do anything either.

 Outputs statistical information related to the content of the table foo.

 Collects statistical information related to the content of the table foo

 Collects statistical information related to the content of the database test

Answer : Collects statistical information related to the content of the table foo

It is possible to backup a database cluster by copying the entire data directory. Select two

suitable descriptions regarding this backup method.


A. The backup data will be a text file consisting of SQL statements.

B. The database server must be stopped prior to the backup.

C. The "pg_restore" command is used to restore the database.

D. "psql" is used to restore the database.

E. You can use standard tools like "tar" and "rsync" to backup files and directories.

Options are :

 d,e

 b,e

 a,b

 b,c

 c,d

Answer : b,e

The following table called 'company' is defined as follows:

id | name

----+------------------

1 | Pgsql,inc.

2 | Postgres Co.,Ltd

3 | SQL Company.

Select the most appropriate psql command for generating a text file company.txt on the client side

with the following content:

1,"Pgsql,inc."

2,"Postgres Co.,Ltd"

3,SQL Company.

Options are :

 \copy company TO 'company.txt' DELIMITER ','


 \copy company TO "company.txt"

 \copy company TO 'company.txt' WITH DELIMITER AS ','

 \copy company TO company.txt CSV

 \copy company TO 'company.txt' WITH ','

 None

Answer : \copy company TO company.txt CSV

Select the most suitable statement about PostgreSQL from below.

Options are :

 PostgreSQL is shareware.

 There are PostgreSQL GPL license versions and commercial license versions

 You can use PostgreSQL for free; however, the source code is not open to the public

 You need to be pre-registered to use PostgreSQL

 PostgreSQL can be used by everyone free of charge for any purpose, be it private, commercial, or
academic

Answer : PostgreSQL can be used by everyone free of charge for any purpose, be it private, commercial, or
academic

Which psql command do you need to execute to display the list of tables in the currently

connected database?

Options are :

 \dt "database_name"

 \dT

 \dt

 SELECT * FROM pg_table_list;

 SHOW tables;

Answer : \dt

Select one incorrect description about changing the settings of PostgreSQL during operation.
Options are :

 There are parameters that can not be set using the SET command

 Values set by a superuser using the SET command are valid for different connections made later.

 All of the current settings can be displayed using the SHOW ALL command.

 The current value of a parameter can be confirmed using the SHOW command.

 Changes that can be made using the SET command have higher priority than ones in postgresql.conf.

Answer : Values set by a superuser using the SET command are valid for different connections made later.

Select the most suitable statement regarding PostgreSQL's pg_hba.conf configuration file.

Options are :

 krb5 authentication can only be used for local connections

 You cannot set different authentications per user.

 You can set different authentications per table.

 You can use any number of authentication types on a single line.

 The authentication settings in the file are evaluated from the top line to the bottom line

Answer : The authentication settings in the file are evaluated from the top line to the bottom line

Table "t1" is defined below.

Table "t1" has a column "id" of type INTEGER, and a column "name" of type TEXT.

t1:

The following SQL is executed while client "A" is connected. BEGIN;

SELECT * FROM t1 WHERE id = 2 FOR UPDATE;

SELECT * FROM t1 WHERE id = 1 FOR UPDATE; -- (*)

While the second 'SELECT' statement, shown with (*), is being executed, a separate client "B"

connects and executes the following SQL.

Select the correct statement about the execution results.

UPDATE t1 SET name = 'turtle' WHERE id = 2;


Note: the default transaction isolation level is set to "read committed".

Options are :

 The update process for client "B" is blocked until the current connection for client "A" is finished.

 The processes for both clients are blocked, and an error stating that a deadlock has been detected is
generated.

 The update process for client "B" is blocked until the current transaction for client "A" is finished.

 The 'UPDATE' process for client "B" proceeds regardless of the condition of client "A".

Answer : The update process for client "B" is blocked until the current transaction for client "A" is finished.

Select the correct SQL statement which concatenates strings 'ABC' and 'abc' to form 'ABCabc

Options are :

 SELECT cat('ABC', 'abc') FROM pg_operator;

 SELECT 'ABC' + 'abc';

 SELECT 'ABC' || 'abc';

 SELECT 'ABC' + 'abc' FROM pg_operator;

 SELECT 'ABC' . 'abc';

Answer : SELECT 'ABC' || 'abc';

A table named "sample" is defined as below. Select two statements which will generate a

constraint error.

CREATE TABLE sample (

i INTEGER PRIMARY KEY,

j INTEGER,

CHECK ( i > 0 AND j < 0 )

);

A. INSERT INTO sample VALUES (1, 0);

B. INSERT INTO sample VALUES (2, -2);


C. INSERT INTO sample VALUES (3, NULL);

D. INSERT INTO sample VALUES (NULL, -4);

E. INSERT INTO sample VALUES (5, -5);

Options are :

 b,c

 d,e

 a,b

 a,d

Answer : a,d

The "sample" table consists of the following data:

How many rows are returned by executing the following SQL statement? SELECT DISTINCT ON

(data) * FROM sample;

Options are :

 4 rows D. 5 rows

 6 rows

 2 rows

 3 rows

Answer : 3 rows

The table "custom" is defined below.

The "id" column and "introducer" column are of INTEGER type, and the "email" column is of TEXT

type.

id | email| introducer

----+-----------------+------------

2 | aaa@example.com | 1

3 | bbb@example.com | 2
4 | ccc@example.com | 2

Three SQL statements were executed in the following order: INSERT INTO custom

SELECT max(id) + 1, 'ddd@example.com', 4 FROM custom;

UPDATE custom SET introducer = 999

WHERE email = 'bbb@example.com';

DELETE FROM custom

WHERE introducer NOT IN (SELECT id FROM custom);

Select the number of rows in the "custom" table after the execution.

Options are :

 2 rows

 0 rows

 4 rows

 3 rows

 1 row

Answer : 2 rows

Given the following two table definitions, select one SQL statement which will cause an error.

CREATE TABLE sample1 (id INTEGER, data TEXT);

CREATE TABLE sample2 (id INTEGER);

Options are :

 SELECT id AS data, data FROM sample1;

 D. SELECT s1.id, s2.id FROM sample1 s1, sample2 s2

 SELECT s1.id, s2.id FROM sample1 AS s1, sample1 AS s2;

 SELECT s1.id, s2.data FROM sample1 s1, sample2 s2;

 SELECT id, id FROM sample1;

Answer : SELECT s1.id, s2.data FROM sample1 s1, sample2 s2;


SQL statements were executed in the following order:

CREATE TABLE fmaster

(id INTEGER PRIMARY KEY, name TEXT);

CREATE TABLE ftrans

(id INTEGER REFERENCES fmaster (id), stat INTEGER, date DATE);

INSERT INTO fmaster VALUES (1, 'itemA');

INSERT INTO ftrans VALUES (1, 1, CURRENT_DATE);

Select two SQL statements that will generate an error when executed next.

A. INSERT INTO ftrans VALUES (1, 1, CURRENT_DATE);

B. INSERT INTO ftrans VALUES (2, 1, '2007-07-07');

C. UPDATE fmaster SET name = 'itemAX' WHERE id = 1;

D. UPDATE fmaster SET id = 100 WHERE id = 1;

E. UPDATE ftrans SET id = 200 WHERE id = 1;

Options are :

 b,c

 c,d

 a,b

 d,e

 a,c

Answer : a,c

The following SQL statements were executed using psql.

Select the appropriate statement about the result.

LISTEN sign_v;

BEGIN;

NOTIFY sign_v;
COMMIT;

LISTEN sign_v;

Options are :

 At the point that 'SELECT * FROM pg_user;" is executed, a message that starts with "Asynchronous
notification 'sign_v' received" is output.

 The message "Asynchronous notification 'sign_v' received" is not received while in this connection.

 When 'LISTEN sign_v' is executed for the second time, a message that starts with "Asynchronous
notification 'sign_v' received" is output.

 At the point that 'NOTIFY sign_v' is executed, a message that starts with "Asynchronous notification
'sign_v' received" is output

 At the point that 'COMMIT' is executed, a message that starts with "Asynchronous notification 'sign_v'
received" is output

Answer : At the point that 'COMMIT' is executed, a message that starts with "Asynchronous notification
'sign_v' received" is output

Select two correct descriptions about views.

A. A view is created by 'DECLARE VIEW', and deleted by 'DROP VIEW'.

B. A view is a virtual table which does not exist.

C. A view is created to simplify complicated queries.

D. You can create a view with the same name as already existing tables.

E. A view only exists while the postmaster is running, and is deleted when the postmaster stops.

Options are :

 b,c

 d,e

 b,d

 a,b

Answer : b,c

Four SQL statements were executed in the following order. CREATE TABLE foo (bar INT);
ALTER TABLE foo ALTER bar TYPE BIGINT;

ALTER TABLE foo ADD baz VARCHAR(5);

ALTER TABLE foo DROP bar;

Select two SQL statements that generate an error when executed.

A. INSERT INTO foo VALUES ('12345');

B. INSERT INTO foo VALUES ('5000000000');

C. INSERT INTO foo VALUES ('ABC');

D. INSERT INTO foo VALUES (2000000000);

E. INSERT INTO foo VALUES (NULL);

Options are :

 c,d

 a,b

 d,e

 b,c

Answer : a,b

Select two suitable statements about sequences.

A. A sequence always returns a 4-byte INTEGER type value, so the maximum value is

2147483647.

B. A sequence is defined by 'CREATE SEQUENCE', and deleted by 'DROP SEQUENCE'.

C. Although the "nextval" function is called during a transaction, it will have no effect if that

transaction is rolled back.

D. A sequence always generates 0 or consecutive positive numbers.

E. A sequence number can be set by calling the "setval" function

Options are :

 c,d
 d,e

 b,e

 a,b

Answer : b,e

Table "t1" is defined as follows:

CREATE TABLE t1 (value VARCHAR(5));

A set of SQL statements were executed in the following order. Select the number of rows that

table "t1" has after execution.

BEGIN;

INSERT INTO t1 VALUES ('AA');

SAVEPOINT point1;

INSERT INTO t1 VALUES ('BB');

SAVEPOINT point2;

INSERT INTO t1 VALUES ('CC');

ROLLBACK TO point1;

INSERT INTO t1 VALUES ('DD');

Options are :

 2 rows

 1 row

 0 rows

 3 rows

 4 rows

Answer : 2 rows

Select two suitable statements regarding the following SQL statement:

CREATE TRIGGER trigger_1 AFTER UPDATE ON sales FOR EACH ROW EXECUTE
PROCEDURE write_log();

A. It is defining a trigger "trigger_1".

B. Every time 'UPDATE' is executed on the "sales" table, the "write_log" function is called once.

C. The "write_log" function is called before 'UPDATE' takes place.

D. 'UPDATE' is not executed if "write_log" returns NULL.

E. 'DROP TRIGGER trigger_1 ON sales;' deletes the defined trigger.

Options are :

 a,e

 a,b

 b,c

 c,d

Answer : a,e

Select three SQL statements which return NULL.

A. SELECT 0 = NULL;

B. SELECT NULL != NULL;

C. SELECT NULL IS NULL;

D. SELECT NULL;

E. SELECT 'null'::TEXT;

Options are :

 a,b,d

 a,b,c

 b,c,d

 c,d,e

Answer : a,b,d

The "sample" table consists of the following data:


How many rows are returned by executing the following SQL statement? SELECT * FROM

sample WHERE v ~ 'ab';

Options are :

 0 rows

 4 rows

 2 rows

 3 rows

 1 row

Answer : 2 rows

The tables "t1" and "t2" are defined below.

The tables "t1" and "t2" have columns "id" which are type of INTEGER and column "name"s which

are type of TEXT.

t1

t2

The following SQL command was executed. Select the number of rows in the result. SELECT *

FROM t1 NATURAL FULL OUTER JOIN t2;

Options are :

 2 rows

 3rows

 6 rows

 5 rows

 4 rows

Answer : 5 rows

 Select two transaction isolation levels supported in PostgreSQL.

A. DIRTY READ
B. READ COMMITTED

C. REPEATABLE READ

D. PHANTOM READ

E. SERIALIZABLE

Options are :

 d,e

 c,d

 a,b

 b,e

 c,b

Answer : b,e

The table "score" is defined as follows:

gid | score

-----+-------

1| 70

1| 60

2| 100

3| 80

3| 50

The following query was executed. Select the number of rows in the result. SELECT gid,

max(score) FROM score

GROUP BY gid HAVING max(score) > 60;

Options are :

 5 rows

 2 rows
 1 row

 3 rows

 4 rows

Answer : 3 rows


Set 3

psql generated the following error message:

psql: could not connect to server: Connection was refused

Is the server running on host "server.example.com" and accepting

PostgreSQL CE PGCES-02 Exam

BrainDumps.

TCP/IP connections on port 5432?

Select two reasons that are NOT the cause of this error.

A. Host "server.example.com" does not exist.

B. The PostgreSQL server is not running on "server.example.com".

C. The PostgreSQL server is not accepting TCP/IP connections on "server.example.com".

D. The PostgreSQL server is running on a port other than 5432 on "server.example.com".

E. The username and/or password are incorrect

Options are :

 a,b

 d,e

 b,c

 c,d

Answer : a,b

Select two incorrect statements about the function of the information schema.

A. It consists of a group of views included in a schema called "information_schema".

B. Information on objects defined in a database can be referenced.

C. The number of tables defined in a database can be confirmed.


D. Administrator privileges are needed to reference the information schema.

E. In order to enable the information schema, "information_schema = true" must be set in

postgresql.conf

Options are :

 d,e

 a,e

 a,b

 b,c

Answer : d,e

Select two correct statements from below concerning the ANALYZE command.

A. It renews the statistical information of the table content.

B. It takes some time to execute, but it does not lock the table.

C. If the FULL option is used when executing, the size of the file can be reduced.

D. If ANALYZE is insufficient, the most efficient search plan will not be selected for queries.

E. If ANALYZE is not used at all, there are times when it becomes impossible to see any of the

data.

Options are :

 c,d

 d,e

 None

 a,b

 a,d

Answer : a,d

Select one incorrect statement about the SQL COPY command.


Options are :

 Only the superuser can specify the output file name.

 Copies row data from a file into a table.

 The delimiter that separates column data can be changed from the default TAB character.

 You can output the row data of a table to a specified client side file.

 It copies data between a file and a table.

Answer : You can output the row data of a table to a specified client side file.

Select a correct SQL command to change existing user "george"'s password to "foobar".

Options are :

 ALTER USER george CHANGE PASSWORD 'foobar';

 SET USER george PASSWORD TO 'foobar

 ALTER USER george WITH PASSWORD 'foobar';ALTER USER george CHANGE PASSWORD
'foobar';

 SET USER george ALTER PASSWORD 'foobar';

 ALTER USER george SET PASSWORD 'foobar

Answer : ALTER USER george WITH PASSWORD 'foobar';ALTER USER george CHANGE PASSWORD
'foobar';

Select one incorrect statement from the below about a database cluster.

Options are :

 When a database cluster is created, a database superuser is registered using the username of the OS at
the time of creation unless otherwise designated.

 Special databases called template0 and template1 are created in a database cluster by default.

 It is possible to have multiple databases within a database cluster

 A database cluster is created using initdb command.

 Each host can have only one database cluster

Answer : Each host can have only one database cluster


Select one SQL statement that will cause an error.

Options are :

 SELECT current_database();

 SELECT version

 SELECT current_date;

 SELECT current_user;

 SELECT current_timestamp;

Answer : SELECT version

Select two suitable statements regarding a postmaster process.

A. A postmaster process waits for client connection requests.

B. A postmaster process receives and processes database queries.

C. A postmaster process creates a child process which processes the given queries.

D. A postmaster process collects statistical information.

E. A postmaster process is created for each client connection.

Options are :

 c,b

 a,b

 d,e

 a,c

Answer : a,c

What does the following command do? Choose one incorrect statement from the selection below.

$ pg_dumpall -U postgres > 20060601.bak

Options are :

 Backup all the databases in a database cluster.


 You can access databases while the backup is in process.

 Backup with plain-text format.

 Backup postgresql.conf along with databases.

 Backup user and group information along with databases.

Answer : Backup postgresql.conf along with databases.

Select two commands below from which privileges cannot be changed by the GRANT and REVOKE
statements.

A. SELECT

B. VACUUM

C. DELETE

D. TRIGGER

E. DROP

Options are :

 c,d

 b,c

 a,b

 b,e

Answer : b,e

Select the most suitable statement about the creation of a new database

Options are :

 Only the OS superuser (root) can create databases.

 The target directory is specified by the environment variable PGDATA or the -D parameter when
creating a database

 Only one database can be used at the same time even if two or more databases are created

 You can set the character encoding when creating a new database.

 Only a PostgreSQL superuser is authorized to create a new database. (Incorrect)


Answer : You can set the character encoding when creating a new database.

The following are statements related to the postmaster. Select one statement that is incorrect.

Options are :

 The "pg_ctl stop" command stops postmaster.

 None

 It is not possible to boot up the postmaster process by directly executing the postmaster command.

 postmaster is a server process that receives connections from clients

 One postmaster process controls one database cluster.

 The "pg_ctl start" command boots up postmaster.

Answer : It is not possible to boot up the postmaster process by directly executing the postmaster command.

What does the following command do? Choose two incorrect statements from the selection below.

Note: $ is the command prompt.

$ pg_restore -U postgres -d database1 database1.dump

A. This command restores the database database1 from the file database1.dump.

B. This command connects to a database as the user 'postgres'.

C. This command can not be executed unless the postmaster is running.

D. This command can not restore large objects.

E. This command must be executed under the condition where the database database1 does

not exist.

Options are :

 C,D

 D,E

 A,E

 A,B
Answer : D,E

Select one incorrect statement concerning changes from PostgreSQL version 7.4 to 8.0.

Options are :

 Two-phase commit function was added.

 CSV mode was added to the copy command

 SAVEPOINT function was added.

 Point-In-Time Recovery function was added.

 The shared buffer control algorithm was improved

Answer : Two-phase commit function was added.

Based on the relationship of columns within a table, select the most suitable description that

shows that column A is dependent on column B.

Options are :

 When the value in column B is changed, the corresponding value of column A also must be changed.

 The value in column B is uniquely determined when a value in column A is selected

 The value in column A is uniquely determined when a value in column B is selected

 As long as column B exists, the amount of information will not decrease even if column A is deleted.

 When the value in column A is changed, the corresponding value in column B also must be changed.

Answer : The value in column A is uniquely determined when a value in column B is selected

Select one incorrect statement about the command shown below. Note: $ is the command prompt.

$ dropuser -U admin foo

Options are :

 The same process can be performed using the SQL command "DROP USER".

 If there is a database owned by foo, an error will occur.

 The user admin is removing the user foo.


 If admin doesn't have the superuser privilege, an error will occur.

 If admin is not the owner of foo, an error will occur.

Answer : If admin is not the owner of foo, an error will occur.

Select two incorrect statements concerning the system catalog

A. It stores the object definition information for tables and columns.

B. There may be changes to specification by major version upgrades.

C. It is accessible as a table; however, it is output in binary format so it can not be read as is.

D. It stores the internal information of the database management system.

E. It is defined based on the standard SQL specification

Options are :

 c,d

 b,c

 a,b

 c,e

Answer : c,e

Select one false statement about the benefits of using database management systems from

below.

Options are :

 You can separate the data storage method from the application

 You can separate the data search method from the application.

 None of the above

 You can share data more easily on systems consisting of multiple computers.

 You can separate the data display method from the application

 You can reduce the programming workload of programming for managing data.

Answer : You can separate the data display method from the application
Select two incorrect statements related to the command below. Note: $ is the command prompt.

$ psql -U foo -c "COPY company TO stdout;" bar

A. If the company table is not readable, an error occurs.

B. The content of the company table is written into a file called 'stdout'.

C. The content of the company table is output in TAB delimited format.

D. An error occurs unless the user foo has administrator privileges.

E. Connects to the database bar.

Options are :

 a,b

 b,d

 c,d

 b,c

Answer : b,d

I would like to check the privileges on the "items" table in psql. Select the most appropriate

command.

Options are :

 \d items

 \a items

 \t items

 \p items

 \z items

Answer : \z items

The following question concerns the use of multibyte characters in PostgreSQL.

Select two correct items about character encoding in PostgreSQL.

A. "./configure --enable-multibyte" must be designated at time of build.


B. When the database cluster is initialized, the or --multibyte option must be specified.

C. Character encoding can be set on a per database basis.

D. Only a single character encoding can be specified for each database cluster.

E. Different character encodings can be specified for server and clients.

Options are :

 c,e

 c,d

 a,b

 b,c

Answer : c,e

I would like to restore the database cluster from the "db1.dump" backup file.

Select the correct command from below. (Note: "postgres" is the superuser)

Options are :

 pg_restore -U postgres -f db1.dump db1

 psql -U postgres -f db1.dump db1

 pg_dump --restore db1 < db1.dump

 pg_resetxlog -U postgres db1 < db1.dump

 pg_dump -U postgres --restore db1 < db1.dump

Answer : psql -U postgres -f db1.dump db1

Select the most appropriate statement about the initdb command.

Options are :

 The directory designated by the environment variable PGDATA must exist

 It can not be executed by an OS administrator-level user (root user).

 When "auto" is designated as the value for the environment variable PGDATA, a directory is
automatically set up.
 It can only be executed by the user who installed PostgreSQL.

 Unless the environment variable PGDATA is set, it can not be executed

Answer : It can not be executed by an OS administrator-level user (root user).

What does the following command do? Choose the most appropriate statement from the selection

below.

Note: $ is the command prompt.

$ pg_dump postgres > pgsql

Options are :

 Backs up the database postgres and writes an error message to the file pgsql.

 Outputs all of the content of the database postgres to the screen using the user pgsql.

 Writes a backup of the database postgres to the file pgsql.

 Writes a backup of the entire database cluster using user postgres to the file pgsql.

 Writes a backup of the entire database cluster to the file postgres and writes an error message to the file
pgsql.

Answer : Writes a backup of the database postgres to the file pgsql.

Select an appropriate command to check the PostgreSQL version in psql.

Options are :

 SHOW version

 SELECT version;c

 \server_version

 SELECT version();

 SHOW server;

Answer : SELECT version();

I want to restore data from a text format backup file foo.dump. Select an appropriate command.

Options are :
 psql -f foo.dump foo

 pg_dump -R foo < foo.dump

 pg_restore -d foo foo.dump

 pg_restore -f foo.dump foo

 createdb foo < foo.dump

Answer : psql -f foo.dump foo

What phenomenon occurs if PostgreSQL is used without performing VACUUM ?

Select two appropriate descriptions from those below.

A. Performance is reduced.

B. It gradually gets to the point where connections are denied.

C. The physical size of the database increases considerably in size.

D. Only SELECT queries will be accepted.

E. An e-mail prompting the administrator to perform VACUUM is sent from PostgreSQL

Options are :

 a,b

 b,c

 a,c

 c,d

Answer : a,c
Set -4

You want to delete rows in the "product" table which include the value '2004' in the "name" field.

Select the correct statement to achieve this task.

Options are :

 DELETE FROM product WHERE name LIKE '%2004%';

 DELETE product WHERE contain(name, '2004');

 DELETE FROM product WHERE name SIMILAR TO '2004';

 DELETE product WHERE name ~ '2004';

 DELETE FROM product WHERE name IN '2004';

Answer : DELETE FROM product WHERE name LIKE '%2004%';

The table "t1" is defined by the following SQL statement: CREATE TABLE t1 (id integer, name

varchar(20));

You want to increase the execution speed of the SQL statement below:

SELECT id, name FROM t1 WHERE id < 123 AND upper(name) = 'MAMMOTH'; Select the most

suitable SQL statement to create an index.

Options are :

 ALTER TABLE ADD INDEX ON t1 (id, name);

 ALTER TABLE ADD INDEX ON t1 (id, upper(name));

 CREATE INDEX t1_idx ON t1 (name);

 CREATE INDEX t1_idx ON t1 USING HASH (id);

 CREATE INDEX t1_idx ON t1 (id, upper(name));

Answer : CREATE INDEX t1_idx ON t1 (id, upper(name));


In the "customer" table, you want to change the "email" values which have an "id" value of 10000

or less, to NULL. Select the correct SQL statement to achieve this task.

Options are :

 UPDATE customer SET email = NULL WHERE id <= 10000;

 DELETE FROM customer.email WHERE id < 10001;

 UPDATE email = NULL FROM customer WHERE id <= 10000;

 UPDATE customer SET email IS NULL WHERE id < 10001

 UPDATE FROM customer SET email = NULL WHERE id <= 10000;

Answer : UPDATE customer SET email = NULL WHERE id <= 10000;

A table is defined as below. Select the most suitable description about the foreign key constraint.

CREATE TABLE master (id INTEGER PRIMARY KEY, name TEXT); CREATE TABLE record (id
INTEGER REFERENCES master (id), count INTEGER);

Options are :

 If the "record" table contains a row with an "id", the corresponding "id" row in the "master" table
cannot be deleted.

 These SQL statements are invalid; no constraints are created

 The "record" table cannot have duplicate "id"s.

 If any row exists in the "record" table, no change can be made to the "master" table

 If the "record" table contains a row with an "id", no change can be made at all to the corresponding "id"
row in the "master" table.

Answer : If the "record" table contains a row with an "id", the corresponding "id" row in the "master" table
cannot be deleted.

Select two appropriate statements from below about the following SQL statements:

CREATE FUNCTION myfunc(INTEGER) RETURNS text LANGUAGE plpgsql STRICT AS '

DECLARE

x ALIAS FOR $1;

r text := ''default'';
BEGIN

IF x > 100 THEN

SELECT INTO r data FROM mytable WHERE id = x; END IF;

RETURN r;

END;';

A. An error is generated unless the plpgsql language is registered in the database beforehand.

B. The execution results of SELECT myfunc(-123) differs based on the content of "mytable".

C. When SELECT myfunc(123) is executed an error occurs.

D. When SELECT myfunc(NULL) is executed an error occurs.

E. When SELECT myfunc (0) is executed the text "default" is returned.

Options are :

 a,e

 d,e

 a,b

 b,c

Answer : a,e

You want to create a cursor that will SELECT the "customer" table. The created cursor must be

able to move in any direction and reference data even after the end of the transaction.

Select one answer containing the correct keyword(s) to fill in the underlined blank below.

DECLARE cursor1 __________ FOR SELECT * FROM customer;

Options are :

 NO SCROLL CURSOR WITH HOLD

 CURSOR

 SCROLL CURSOR WITH HOLD

 INSENSITIVE CURSOR
 CURSOR WITHOUT HOLD

Answer : SCROLL CURSOR WITH HOLD

The tables "s1" and "s2" are defined below.

The column "id" for tables "s1" and "s2" is of INTEGER type. The column "enable" for table "s1" is

of

BOOLEAN type, and the column "name" for table "s2" is of TEXT type.

s1:

id | enable

----+--------

1|t

2|f

s2:

id | name

----+------

1 | post

2 | gre

3 | SQL

The following SQL was executed. Select the correct number of rows in the result. SELECT *

FROM s2 WHERE id IN (SELECT id FROM s1);

Options are :

 2row

 3row

 4row

 1 row

 5row
Answer : 2row

What happens if an SQL statement syntax error occurs while a transaction is running? Select the

correct action from below.

Options are :

 The transaction is stopped and you cannot issue any SQL commands other than a command to end the
transaction

 The transaction is aborted and a new transaction is started automatically

 The "postmaster" process is terminated

 The transaction continues

 The connection is terminated.

Answer : The transaction is stopped and you cannot issue any SQL commands other than a command to end
the transaction

The "sample" table consists of the data below. The column "x" is of type INTEGER. How many

rows are returned by executing the following SQL statement?

SELECT 6 / x FROM sample

WHERE CASE WHEN x = 0 THEN FALSE ELSE TRUE END;

Options are :

 ERROR division by zero" and no rows are returned.

 0 rows with no errors

 3 rows

 2 rows

 1 row

Answer : 2 rows

Which normal form has the constraint that there must be no tables with duplicate column values in

the same row?


Options are :

 Third normal form

 Boyce/Codd normal form

 Fourth normal form

 Second normal form

 First normal form

Answer : First normal form

There is a table "tb1" that has a column "c1" defined as type TEXT. The following SQL is executed

while client "A" is connected.

BEGIN;

LOCK TABLE tb1 IN ACCESS EXCLUSIVE MODE; SELECT * FROM tb1;

While the above 'SELECT' statement is being executed, client "B" connects to the same database

and executes the following SQL.

Select two correct statements describing the behavior of PostgreSQL.

INSERT INTO tb1 (c1) VALUES ('new line');

Note: the default transaction isolation level is set to "read committed".

A. The process for client "B" is blocked until the current connection for client "A" is finished.

B. The process for client "B" is blocked until the current transaction for client "A" is finished.

C. The process for client "B" will be deleted regardless of the condition of client "A".

D. The process of client "B" will affect the SELECT result of client "A".

E. The process of client "B" will not affect the SELECT result of client "A".

Options are :

 b,e

 a,b

 b,c
 c,d

 d,e

Answer : b,e

The following SQL defines an INSERT with respect to item_view.

Select the keyword that is applicable in the underlined blank.

CREATE _______ foo AS ON INSERT TO item_view

DO INSTEAD INSERT INTO item_table VALUES (NEW.id, NEW.itemname);

Options are :

 VIEW

 TRIGGER

 CONSTRAINT

 FUNCTION

 RULE

Answer : RULE

The tables "t1" and "t2" are defined below.

Tables "t1" and "t2" have columns "id" that are of INTEGER type, and columns "name" that are of

TEXT type.

t1

t2

The following SQL command was executed. Select the number of rows in the result. SELECT *

FROM t1 RIGHT OUTER JOIN t2 ON t1.id = t2.id;

Options are :

 6rows

 4rows

 2 rows
 5rows

 3rows

Answer : 3rows

Select the correct SQL statement to define a new data type.

Options are :

 CREATE TYPE

 CREATE OPERATOR

 CREATE FUNCTION

 CREATE DATABASE

 CREATE CLASS

Answer : CREATE TYPE

Select the SQL command that must be executed prior to executing the EXECUTE command.

Options are :

 PREPARE

 CREATE FUNCTION

 DECLARE

 ALLOCATE

 LOAD

Answer : PREPARE

table and view are defined as follows:

CREATE TABLE item (id INT, name TEXT, description TEXT);

CREATE VIEW item_simple AS SELECT id, name FROM item;

A set of SQL statements were executed in the order below. Select the most appropriate statement

concerning the execution results.

BEGIN;
SELECT * FROM item_simple;

INSERT INTO item_simple VALUES (1, 'item_name_1');

UPDATE item_simple SET name = 'item_name_2' WHERE id = 1; DELETE FROM item_simple;

END;

Options are :

 An error is generated at the point the SELECT statement is executed

 No error is generated

 An error is generated at the point the INSERT statement is executed.

 An error is generated at the point the UPDATE statement is executed.

 An error is generated at the point the DELETE statement is executed

Answer : An error is generated at the point the INSERT statement is executed.

Given the following two table definitions, select one SQL statement which will cause an error.

CREATE TABLE sample1 (id INTEGER, data TEXT);

CREATE TABLE sample2 (id INTEGER);

Options are :

 SELECT s1.id FROM sample1 s1;

 SELECT data FROM sample1 AS s1, sample2 AS s2 WHERE s1.id = 1 AND s2.id = 2;

 SELECT s1.id, s1.data FROM sample1 AS s1, sample2 AS s2 WHERE s1.id = s2.id;

 SELECT id, data FROM sample1 AS s1, sample2 AS s2 WHERE s1.id = s2.id;

 SELECT s1.id FROM sample1 AS s1;

Answer : SELECT id, data FROM sample1 AS s1, sample2 AS s2 WHERE s1.id = s2.id;

Select two suitable statements about the BSD license from below.

A. If you make changes to the source code, feedback must be sent to the original developers.

B. It is used by open source software.

C. User registration is required.


D. It is defined by Free Software Foundation, Inc. (FSF).

E. Software under the BSD license can be incorporated with any programs provided that the

copyright notice appears in all copies.

Options are :

 a,b

 b,c

 a,e

 c,d

Answer : a,e

The tables "t1" and "t2" are defined in the same way (they have the same data types and column

names). You want to select rows in "t1" which are not in "t2".

Select a correct keyword to fill in the blank below.

SELECT * FROM t1 ______ SELECT * FROM t2;

Options are :

 INTERSECT ALL

 EXCEPT

 NAND

 INTERSECT

 UNION

Answer : EXCEPT

Select the correct result generated by execution of the following SQL statements: CREATE

TABLE log (id int, message TEXT, logtime TIMESTAMP);

CREATE TABLE log_01 () INHERITS (log);

INSERT INTO log_01 VALUES (1, 'error', CURRENT_TIMESTAMP); SELECT * FROM log;
Options are :

 SELECT' statement returns 1 row, and exits successfully.

 'SELECT' statement returns 0 rows, and exits successfully.

 Second 'CREATE TABLE' generates a syntax error.

 'INSERT' statement generates an error stating that the number of columns and values do not match".

 First 'CREATE TABLE' generates a syntax error.

Answer : SELECT' statement returns 1 row, and exits successfully.

The present time is noon of July 7th, 2007, and the result of the following

SQL sentence was '2007-07-17 12:00:00'.

Select the correct expression to fill in the blank below.

SELECT CURRENT_TIMESTAMP::timestamp + ________________ ;

Options are :

 age(8640000

 '10 day'::timestamp

 '10 day'::interval

 8640000::time

 10::day

Answer : age(8640000

Select one incorrect description regarding the following SQL statement defining a function.

CREATE OR REPLACE FUNCTION get_file_list(TEXT, BOOLEAN)

RETURNS SETOF TEXT LANGUAGE C STRICT

SECURITY DEFINER AS 'myfuncs.so';

Options are :

 This function may be defined in 'myfuncs.so'.

 If this function is called with a NULL parameter, it will return 0 when executed
 This function operates with the authority of the user who executed it.

 This function can return multiple rows.

 This SQL statement defines a function written in the C language.

Answer : This function operates with the authority of the user who executed it.

The "sample" table consists of the following data.

How many rows are returned by executing the following SQL statement?

SELECT i FROM sample GROUP BY i;

Options are :

 1row

 3row

 4row

 2row

 5row

Answer : 3row

The table "tbl" is defined below such that it could only store non-negative integers in the column

"nn".

Select the keyword that is applicable for the underlined blank.

CREATE _______ natural_number AS DECIMAL CHECK (VALUE >= 0); CREATE TABLE tbl(nn

natural_number);

Options are :

 DOMAIN

 SCHEMA

 VIEW

 TYPE

 RULE
Answer : DOMAIN

You want to set a constraint so that the "item_id" in the "sales" table will always have a value that

already exists as "id" in the "item_master" table. Select the correct SQL statement to fill in the

underlined blank of the "sales" table. Definitions:

CREATE TABLE item_master (

id INTEGER PRIMARY KEY,

name TEXT

);

CREATE TABLE sales (

sales_id INTEGER,

item_id INTEGER,

num INTEGER,

);

Options are :

 REFERENCES item_master (item_id)

 REFERENCES item_master (id)

 REFERENCES item_master (id) TO item_id

 FOREIGN KEY (id) REFERENCES item_master (item_id)

 FOREIGN KEY (item_id) REFERENCES item_master (id)

Answer : FOREIGN KEY (item_id) REFERENCES item_master (id)

A set of tables are defined as follows:

t1

t2

How many rows are returned by executing the following SQL statement?

SELECT t1.name FROM t1 CROSS JOIN t2;


Options are :

 3 rows

 0 rows

 2 rows

 6 rows

 5 rows

Answer : 6 rows

Select two incorrect statements regarding large objects.

A. A large object is generated by 'CREATE LARGE OBJECT'.

B. A large object is added by 'INSERT'.

C. One large object is able to handle up to 2GB of data.

D. Binary data cannot be used unless declared as a large object.

E. An OID is used to identify a large object.

Options are :

 b,c

 c,e

 a,b

 c,d

Answer : c,e

Select two SQL statements which abort a transaction.

A. END

B. ROLLBACK

C. TRUNCATE

D. ABORT

E. DROP TRANSTACTION
Options are :

 b,d

 a,b

 c,d

 b,c

Answer : b,d
Set 5

Select two suitable statements regarding the data types of PostgreSQL.

A. One field can handle up to 1GB of data.

B. 'n' in CHARACTER(n) represents the number of bytes.

C. Only the INTEGER type can be declared as an array.

D. There is a non-standard PostgreSQL data type, called Geometric data type, which handles 2-

dimensional data.

E. A large object data type can be used to store data of unlimited size.

Options are :

 a,d

 a,b

 b,c

 c,d

Answer : a,d

Select two suitable statements about major version upgrades of PostgreSQL from below.

A. You can use the databases of the old major version.

B. To use the data from the old version, you only need to replace the program.

C. To use the data from the old version, you need to conduct a backup and restore.

D. There is a possibility of configuration parameter changes after major version upgrades.

E. Upgrade scripts can be executed while the old version of PostgreSQL is running.

Options are :

 d,e

 c,d

 a,b

 b,c
Answer : c,d

Select an incorrect statement regarding the following SQL statement. Note that "user_view" is a

view.

CREATE OR REPLACE RULE rule_1 AS ON UPDATE TO user_view DO INSTEAD NOTHING;

Options are :

 It is defining a rule "rule_1".

 It will replace "rule_1" if it already exists.

 'DROP RULE rule_1 ON user_view' deletes the above definition

 Executing 'UPDATE user_view' will no longer output errors.

 When executing 'UPDATE user_view', data is updated in the table that is the origin of the view.

Answer : When executing 'UPDATE user_view', data is updated in the table that is the origin of the view.

Select two incorrect statements regarding 'DOMAIN'.

A. When defining a domain, you can add a default value and constraints to the original data.

B. Domain is a namespace existing between databases and objects such as tables.

C. A domain is created by 'CREATE DOMAIN'.

D. A domain can be used as a column type when defining a table.

E. To define a domain, both input and output functions are required.

Options are :

 b,e

 a,b

 b,c

 c,d

Answer : b,e

PostgreSQL can use an index to access a table. Select two incorrect statements about indexes.
A. An index is created by 'CREATE INDEX', and deleted by 'DROP INDEX'.

B. By using an index effectively, searching and sorting performs faster.

C. There are B-tree, Hash, R-tree and GiST index types.

D. By creating an index, performance always improves.

E. Creating an unused index does not affect the performance of a database at all.

Options are :

 d,e

 c,d

 a,b

 a,e

Answer : d,e

The following is the result of executing the createlang command which is installed with

PostgreSQL.

$ createlang -U postgres --list mydb

Procedural Languages

Name | Trusted?

---------+----------

plpgsql | yes

Select two correct statements from below.

A. The procedural language plpgsql is installed in the database mydb using the above command.

B. The procedural language plpgsql can be used in the database mydb.

C. plpgsql is a trusted language, so it can execute the OS commands on the server side.

D. plpgsql is a trusted language, so it can read/write OS files on the server side.

E. plpgsql is a safe language with restricted operations.

Options are :
 a,b

 b,c

 d,e

 c,d

Answer : d,e

Select two suitable statements regarding creating a new table.

A. There is no upper limit to the number of columns in a table.

B. A newly created table is empty and has 0 rows

C. You can only use alphabetic characters for a table name.

D. The row name must be within 16 characters.

E. The SQL 'CREATE TABLE' statement is used to create a new table.

Options are :

 d,e

 b,e

 a,b

 c,d

 b,c

Answer : b,e

You want to delete rows in the "product" table which include the value '2004' in the "name" field.

Select the correct statement to achieve this task.

Options are :

 DELETE FROM product WHERE name LIKE '%2004%';

 DELETE product WHERE contain(name, '2004');

 DELETE FROM product WHERE name SIMILAR TO '2004';

 DELETE product WHERE name ~ '2004';


 DELETE FROM product WHERE name IN '2004';

Answer : DELETE FROM product WHERE name LIKE '%2004%';

The table "t1" is defined by the following SQL statement: CREATE TABLE t1 (id integer, name

varchar(20));

You want to increase the execution speed of the SQL statement below:

SELECT id, name FROM t1 WHERE id < 123 AND upper(name) = 'MAMMOTH'; Select the most

suitable SQL statement to create an index.

Options are :

 ALTER TABLE ADD INDEX ON t1 (id, name);

 ALTER TABLE ADD INDEX ON t1 (id, upper(name));

 CREATE INDEX t1_idx ON t1 (name);

 CREATE INDEX t1_idx ON t1 USING HASH (id);

 CREATE INDEX t1_idx ON t1 (id, upper(name));

Answer : CREATE INDEX t1_idx ON t1 (id, upper(name));

In the "customer" table, you want to change the "email" values which have an "id" value of 10000

or less, to NULL. Select the correct SQL statement to achieve this task.

Options are :

 UPDATE customer SET email = NULL WHERE id <= 10000;

 DELETE FROM customer.email WHERE id < 10001;

 UPDATE email = NULL FROM customer WHERE id <= 10000;

 UPDATE customer SET email IS NULL WHERE id < 10001

 UPDATE FROM customer SET email = NULL WHERE id <= 10000;

Answer : UPDATE customer SET email = NULL WHERE id <= 10000;

A table is defined as below. Select the most suitable description about the foreign key constraint.
CREATE TABLE master (id INTEGER PRIMARY KEY, name TEXT); CREATE TABLE record (id
INTEGER REFERENCES master (id), count INTEGER);

Options are :

 If the "record" table contains a row with an "id", the corresponding "id" row in the "master" table
cannot be deleted.

 These SQL statements are invalid; no constraints are created

 The "record" table cannot have duplicate "id"s.

 If any row exists in the "record" table, no change can be made to the "master" table

 If the "record" table contains a row with an "id", no change can be made at all to the corresponding "id"
row in the "master" table.

Answer : If the "record" table contains a row with an "id", the corresponding "id" row in the "master" table
cannot be deleted.

Select two appropriate statements from below about the following SQL statements:

CREATE FUNCTION myfunc(INTEGER) RETURNS text LANGUAGE plpgsql STRICT AS '

DECLARE

x ALIAS FOR $1;

r text := ''default'';

BEGIN

IF x > 100 THEN

SELECT INTO r data FROM mytable WHERE id = x; END IF;

RETURN r;

END;';

A. An error is generated unless the plpgsql language is registered in the database beforehand.

B. The execution results of SELECT myfunc(-123) differs based on the content of "mytable".

C. When SELECT myfunc(123) is executed an error occurs.

D. When SELECT myfunc(NULL) is executed an error occurs.

E. When SELECT myfunc (0) is executed the text "default" is returned.


Options are :

 a,e

 d,e

 a,b

 b,c

Answer : a,e

You want to create a cursor that will SELECT the "customer" table. The created cursor must be

able to move in any direction and reference data even after the end of the transaction.

Select one answer containing the correct keyword(s) to fill in the underlined blank below.

DECLARE cursor1 __________ FOR SELECT * FROM customer;

Options are :

 NO SCROLL CURSOR WITH HOLD

 CURSOR

 SCROLL CURSOR WITH HOLD

 INSENSITIVE CURSOR

 CURSOR WITHOUT HOLD

Answer : SCROLL CURSOR WITH HOLD

The tables "s1" and "s2" are defined below.

The column "id" for tables "s1" and "s2" is of INTEGER type. The column "enable" for table "s1" is

of

BOOLEAN type, and the column "name" for table "s2" is of TEXT type.

s1:

id | enable

----+--------

1|t
2|f

s2:

id | name

----+------

1 | post

2 | gre

3 | SQL

The following SQL was executed. Select the correct number of rows in the result. SELECT *

FROM s2 WHERE id IN (SELECT id FROM s1);

Options are :

 2row

 3row

 4row

 1 row

 5row

Answer : 2row

What happens if an SQL statement syntax error occurs while a transaction is running? Select the

correct action from below.

Options are :

 The transaction is stopped and you cannot issue any SQL commands other than a command to end the
transaction

 The transaction is aborted and a new transaction is started automatically

 The "postmaster" process is terminated

 The transaction continues

 The connection is terminated.


Answer : The transaction is stopped and you cannot issue any SQL commands other than a command to end
the transaction

The "sample" table consists of the data below. The column "x" is of type INTEGER. How many

rows are returned by executing the following SQL statement?

SELECT 6 / x FROM sample

WHERE CASE WHEN x = 0 THEN FALSE ELSE TRUE END;

Options are :

 ERROR division by zero" and no rows are returned.

 0 rows with no errors

 3 rows

 2 rows

 1 row

Answer : 2 rows

Which normal form has the constraint that there must be no tables with duplicate column values in

the same row?

Options are :

 Third normal form

 Boyce/Codd normal form

 Fourth normal form

 Second normal form

 First normal form

Answer : First normal form

There is a table "tb1" that has a column "c1" defined as type TEXT. The following SQL is executed

while client "A" is connected.

BEGIN;
LOCK TABLE tb1 IN ACCESS EXCLUSIVE MODE; SELECT * FROM tb1;

While the above 'SELECT' statement is being executed, client "B" connects to the same database

and executes the following SQL.

Select two correct statements describing the behavior of PostgreSQL.

INSERT INTO tb1 (c1) VALUES ('new line');

Note: the default transaction isolation level is set to "read committed".

A. The process for client "B" is blocked until the current connection for client "A" is finished.

B. The process for client "B" is blocked until the current transaction for client "A" is finished.

C. The process for client "B" will be deleted regardless of the condition of client "A".

D. The process of client "B" will affect the SELECT result of client "A".

E. The process of client "B" will not affect the SELECT result of client "A".

Options are :

 b,e

 a,b

 b,c

 c,d

 d,e

Answer : b,e

The following SQL defines an INSERT with respect to item_view.

Select the keyword that is applicable in the underlined blank.

CREATE _______ foo AS ON INSERT TO item_view

DO INSTEAD INSERT INTO item_table VALUES (NEW.id, NEW.itemname);

Options are :

 VIEW

 TRIGGER
 CONSTRAINT

 FUNCTION

 RULE

Answer : RULE

The tables "t1" and "t2" are defined below.

Tables "t1" and "t2" have columns "id" that are of INTEGER type, and columns "name" that are of

TEXT type.

t1

t2

The following SQL command was executed. Select the number of rows in the result. SELECT *

FROM t1 RIGHT OUTER JOIN t2 ON t1.id = t2.id;

Options are :

 6rows

 4rows

 2 rows

 5rows

 3rows

Answer : 3rows

Select the correct SQL statement to define a new data type.

Options are :

 CREATE TYPE

 CREATE OPERATOR

 CREATE FUNCTION

 CREATE DATABASE

 CREATE CLASS
Answer : CREATE TYPE

Select the SQL command that must be executed prior to executing the EXECUTE command.

Options are :

 PREPARE

 CREATE FUNCTION

 DECLARE

 ALLOCATE

 LOAD

Answer : PREPARE

table and view are defined as follows:

CREATE TABLE item (id INT, name TEXT, description TEXT);

CREATE VIEW item_simple AS SELECT id, name FROM item;

A set of SQL statements were executed in the order below. Select the most appropriate statement

concerning the execution results.

BEGIN;

SELECT * FROM item_simple;

INSERT INTO item_simple VALUES (1, 'item_name_1');

UPDATE item_simple SET name = 'item_name_2' WHERE id = 1; DELETE FROM item_simple;

END;

Options are :

 An error is generated at the point the SELECT statement is executed

 No error is generated

 An error is generated at the point the INSERT statement is executed.

 An error is generated at the point the UPDATE statement is executed.

 An error is generated at the point the DELETE statement is executed


Answer : An error is generated at the point the INSERT statement is executed.

Given the following two table definitions, select one SQL statement which will cause an error.

CREATE TABLE sample1 (id INTEGER, data TEXT);

CREATE TABLE sample2 (id INTEGER);

Options are :

 SELECT s1.id FROM sample1 s1;

 SELECT data FROM sample1 AS s1, sample2 AS s2 WHERE s1.id = 1 AND s2.id = 2;

 SELECT s1.id, s1.data FROM sample1 AS s1, sample2 AS s2 WHERE s1.id = s2.id;

 SELECT id, data FROM sample1 AS s1, sample2 AS s2 WHERE s1.id = s2.id;

 SELECT s1.id FROM sample1 AS s1;

Answer : SELECT id, data FROM sample1 AS s1, sample2 AS s2 WHERE s1.id = s2.id;

Select two suitable statements about the BSD license from below.

A. If you make changes to the source code, feedback must be sent to the original developers.

B. It is used by open source software.

C. User registration is required.

D. It is defined by Free Software Foundation, Inc. (FSF).

E. Software under the BSD license can be incorporated with any programs provided that the

copyright notice appears in all copies.

Options are :

 a,b

 b,c

 a,e

 c,d

Answer : a,e
The tables "t1" and "t2" are defined in the same way (they have the same data types and column

names). You want to select rows in "t1" which are not in "t2".

Select a correct keyword to fill in the blank below.

SELECT * FROM t1 ______ SELECT * FROM t2;

Options are :

 INTERSECT ALL

 EXCEPT

 NAND

 INTERSECT

 UNION

Answer : EXCEPT

Select the correct result generated by execution of the following SQL statements: CREATE

TABLE log (id int, message TEXT, logtime TIMESTAMP);

CREATE TABLE log_01 () INHERITS (log);

INSERT INTO log_01 VALUES (1, 'error', CURRENT_TIMESTAMP); SELECT * FROM log;

Options are :

 SELECT' statement returns 1 row, and exits successfully.

 'SELECT' statement returns 0 rows, and exits successfully.

 Second 'CREATE TABLE' generates a syntax error.

 'INSERT' statement generates an error stating that the number of columns and values do not match".

 First 'CREATE TABLE' generates a syntax error.

Answer : SELECT' statement returns 1 row, and exits successfully.

The present time is noon of July 7th, 2007, and the result of the following

SQL sentence was '2007-07-17 12:00:00'.

Select the correct expression to fill in the blank below.


SELECT CURRENT_TIMESTAMP::timestamp + ________________ ;

Options are :

 age(8640000

 '10 day'::timestamp

 '10 day'::interval

 8640000::time

 10::day

Answer : age(8640000

Select one incorrect description regarding the following SQL statement defining a function.

CREATE OR REPLACE FUNCTION get_file_list(TEXT, BOOLEAN)

RETURNS SETOF TEXT LANGUAGE C STRICT

SECURITY DEFINER AS 'myfuncs.so';

Options are :

 This function may be defined in 'myfuncs.so'.

 If this function is called with a NULL parameter, it will return 0 when executed

 This function operates with the authority of the user who executed it.

 This function can return multiple rows.

 This SQL statement defines a function written in the C language.

Answer : This function operates with the authority of the user who executed it.

The "sample" table consists of the following data.

How many rows are returned by executing the following SQL statement?

SELECT i FROM sample GROUP BY i;

Options are :

 1row

 3row
 4row

 2row

 5row

Answer : 3row

The table "tbl" is defined below such that it could only store non-negative integers in the column

"nn".

Select the keyword that is applicable for the underlined blank.

CREATE _______ natural_number AS DECIMAL CHECK (VALUE >= 0); CREATE TABLE tbl(nn

natural_number);

Options are :

 DOMAIN

 SCHEMA

 VIEW

 TYPE

 RULE

Answer : DOMAIN

You want to set a constraint so that the "item_id" in the "sales" table will always have a value that

already exists as "id" in the "item_master" table. Select the correct SQL statement to fill in the

underlined blank of the "sales" table. Definitions:

CREATE TABLE item_master (

id INTEGER PRIMARY KEY,

name TEXT

);

CREATE TABLE sales (

sales_id INTEGER,
item_id INTEGER,

num INTEGER,

);

Options are :

 REFERENCES item_master (item_id)

 REFERENCES item_master (id)

 REFERENCES item_master (id) TO item_id

 FOREIGN KEY (id) REFERENCES item_master (item_id)

 FOREIGN KEY (item_id) REFERENCES item_master (id)

Answer : FOREIGN KEY (item_id) REFERENCES item_master (id)

You might also like