Oracle__7. Oracle 1Z0-051 Exam - Insert_Update_Delete Statements Flashcards

1
Q

What happens after these 2 statements? CREATE TABLE orders (order_id NUMBER(10) NOT NULL, customer_id Number(8), order_date DATE DEFAULT SYSDATE); INSERT INTO TABLE (order_id, customer_id, order_date) VALUES (1,null,’05-AUG-2010’)

A

The record is inserted with a null for the customer_id

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What happens after these 2 statements? CREATE TABLE orders (order_id NUMBER(10) NOT NULL, customer_id Number(8), order_date DATE DEFAULT SYSDATE); INSERT INTO TABLE (order_id, customer_id, order_date) VALUES (1,12,null)

A

The record is inserted with a null for the customer_id and a default date of today’s date

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What happens after these 2 statements? CREATE TABLE orders (order_id NUMBER(10) NOT NULL, customer_id Number(8), order_date DATE DEFAULT SYSDATE); INSERT INTO TABLE (order_id, customer_id, order_date) VALUES (null,12,null)

A

The record is rejected but the is a null for Order_id

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Are all fields required in an INSERT INTO statement?

A

NoBut all fields declared as NOT NULL must be populated in an INSERT statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Are all columns that have NOT NULL constraints and defaults values required in an INSERT INTO statement?

A

No. All fields that have defaults declared will automatically be populated on an insert into statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the syntax for an insert statement if more than one record?

A

INSERT ALL INTO (field1, field2…) VALUES (exp1, exp2, …) INTO (field1, field2…) VALUES (exp1, exp2, …) INTO (field1, field2…) VALUES (exp1, exp2, …)SELECT * FROM dual;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the syntax of an INSERT statement where the field name list can be eliminated?

A

INSERT INTO table2 SELECT * FROM table1All the field names and data types must match and be in the same order between the 2 tables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What reason would a values clause be used in an insert statement?

A

to insert records using expressions or hard coded values that are not retrieved from other tables?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Is a constraint only enforced by an INSERT operation on the table?

A

NoA constraint is also enforced by an UPDATE operation on a table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The default format for a date column is DD-MON-RR, so on an insert can you insert 10-JANUARY-2014?

A

Yes.Months are implicitly convertedYears are implicitly converted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What will happen with this insert statement? Insert into table (id, statename) values (&id, ‘&statename’);

A

The user will be prompted for the ID then the statename.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What will happen with this insert statement? insert into table(id, statename) values (&id, ‘&&statename’)

A

The user will be prompred for the ID and the statename only the first time. The first statename will be remembered to the user will not be prompted for the statename the subsequent inserts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What can be used in place of the VALUES clause in an INSERT statement?

A

a select statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Is there anything incorrect with this INSERT statement? UPDATE employees SET job = ‘IT’, commission = null where employee = 114;

A

Everything is syntactically correct.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The MERGE command the same as performing what 2 other commands?

A

UPDATE and INSERTThe Merge command will perform an UPDATE and then an INSERT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Can an update be performed on a view that does not have all the table columns defined with NOT NULL?

A

No.All NOT NULL columns must be in the view before the view will allow any updates to the table

17
Q

What is the maximum number of tables in an Update that can be changed?

A

Only 1 table

18
Q

Will this statement produce an error? INSERT INTO (SELECT department_id, department_name, location_id FROM departments WHERE location_id < 2000) VALUES (9999, ‘Entertainment’, 2500);

A

This statement is validThe records will be inserted even though the 2500 value fails the WHERE clause

19
Q

Will this statement produce an error? INSERT INTO (SELECT department_id, department_name, location_id FROM departments WHERE location_id < 2000 WITH CHECK OPTION) VALUES (9999, ‘Entertainment’, 2500);

A

Yes, because the 2500 value fails the where clause because of the WITH CHECK OPTION

20
Q

How many rows can be inserted with an INSERT with a VALUES clause?

A

Only 1 row

21
Q

What is the difference in the return between these 2 statements? DELETE FROM employees WHERE job_id = ‘SA_REP’ AND commission_pct < .2; DELETE FROM (SELECT * FROM employees) WHERE job_id = ‘SA_REP’ AND commission_pct < .2;

A

There is a subquery in the second statement, but the results are the same. Both will delete the same records

22
Q

Will the following statement produce and error? UPDATE (SELECT prod_id, cust_id, quantity_sold, time_id FROM sales) SET time_id = ‘22-MAR-2007’ WHERE cust_id = (SELECT cust_id FROM customers WHERE cust_last_name = ‘Roberts’ AND credit_limit = 600)

A

No. It would execute and restrict modificationsto only the columns specified in the SELECTstatement.The Values statement cannot have a direct subquery, but a field can have a subquery.

23
Q

What is this INSERT statement limiting? INSERT INTO (SELECT * FROM employees WHERE department_id in (20,50) WITH CHECK OPTION) VALUES (emp_id.NEXTVAL, ‘&ename’,’&jobid’,2000,Null,&did);

A

Limiting the user input to department IDs of 20 and 50 because of the WITH CHECK OPTION

24
Q

Will this statement execute without errors? DELETE * FROM tables where name = ‘Carrey’:

A

No.The * is not allowed

25
Q

Will this statement execute without errors? DELETE FROM employees WHERE employee_id = (SELECT employee_d from employees);

A

NoThe subquery returns more than one row.

26
Q

Will this statement execute without errors? UPDATE employee SET firstname = ‘John’ AND lastname = ‘Smith’ WHERE employee_id = 180;

A

No.Replace the AND with a comma and it will be correct.

27
Q

Will this statement execute without errors? INSERT INTO employees(name, hire_date) VALUES (‘John’,01-jan-11)

A

YesQuotes are not needed is the date format matches the default DD-MON-RR

28
Q

Will this statement cause and error? DELETE table1;

A

No.The FROM is not necessary.

29
Q

What is the difference between these two statements? INSERT INTO (SELECT depart_id, depart_name, loc_id FROM departments WHERE loc_id < 2000) VALUES (9999, ‘Entertainment’, 2500); INSERT INTO (SELECT depart_id, depart_name, loc_id FROM departments WHERE loc_id < 2000 WITH CHECK OPTION) VALUES (9999, ‘Entertainment’, 2500);

A

Neither will insert a record because the 2500 is greater than 2000.The first statement will be inserted, but the WITH CHECK OPTION block the insert and gives a syntax error.