oracle(5)

First, multiple choice

1. Add the following options which can be completed to an empty table (STUDENTS) of STUDENT_ID primary key tasks

A:

ALTER TABLE students ADD PRIMARY KEY student_id;

B:

ALTER TABLE students ADD CONSTRAINT PRIMARY KEY (student_id);

C:

ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY student_id;

D:

ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id);

E:

ALTER TABLE students MODIFY CONSTRAINT stud_id_pk PRIMARY KEY (student_id);

Reference answer: D

Analysis:
to add the primary key of existing syntax table:
the ALTER TABLE table_name the ADD CONSTRAINT constraint name PRIMARY KEY (field name);
Note: The name must be enclosed in parentheses

2. The following hr account unlock command is correct ()
A: Update User Account UNLOCK hr;
B: ALTER hr User Account UNLOCK;
C: ALTER User hr UNLOCK;
D: Update User hr UNLOCK;

Answers: B

Analysis:
Fixed grammar.

3. With regard to the following SQL statement, statement is correct?

  CREATE TABLE dept
  (deptno NUMBER(2),
  dname VARCHAR2(14),
  loc VARCHAR2(13));
  ROLLBACK;
  DESCRIBE DEPT;

A: performing the DESCRIBE DEPT display table DEPT structure
B: a ROLLBACK can be released by the table DEPT storage space
C: performing the DESCRIBE DEPT returns an ORA-04043 Error: because the table DEPT does not exist
before only when a ROLLBACK: D COMMIT is performed to correct a DESCRIBE DEPT DEPT table to display the table structure of

Answers: A

Resolve:
1, DDL will be implicitly commit, and rollback to fall back to the place has not been submitted, it will not be affected by the rollback of DDL;
2, the role DESCRIBE DEP is a table showing the structure of the table DEPT;
of course, is the construction of the table statement DDL
combination of these two points is not difficult to draw the right conclusions A.

4.要求有下列表结构
1.an ORDER_ID column of number data type
2.a CUSTOMER_ID column of number data type
3.an ORDER_STATUS column that contains a character data type
4.a DATE_ORDERED column to contain the date the order was placed

And upon insertion of the data required, if ORDER_STATUS no data, the default value is 'PENDING' instead of the following SQL statement is correct ()

A:

  CREATE TABLE orders (
  order_id NUMBER(10),
  customer_id NUMBER(8),
  order_status NUMBER(10) DEFAULT 'PENDING',
  date_ordered DATE );

B:

  CREATE TABLE orders (
  order_id NUMBER(10),
  customer_id NUMBER(8),
  order_status VARCHAR2(10) = 'PENDING',
  date_ordered DATE );

C:

  CREATE OR REPLACE TABLE orders (
  order_id NUMBER(10),
  customer_id NUMBER(8),
  order_status VARCHAR2(10) DEFAULT 'PENDING',
  date_ordered DATE );

D:

  CREATE OR REPLACE TABLE orders (
  order_id NUMBER(10),
  customer_id NUMBER(8),
  order_status VARCHAR2(10) = 'PENDING',
  date_ordered DATE );

E:

  CREATE TABLE orders (
  order_id NUMBER(10),
  customer_id NUMBER(8),
  order_status VARCHAR2(10) DEFAULT 'PENDING',
  date_ordered DATE );

F:

  CREATE TABLE orders (
  order_id NUMBER(10),
  customer_id NUMBER(8),
  order_status VARCHAR2(10) DEFAULT 'PENDING',
  date_ordered VARCHAR2 );

Reference answer: E

Analytical:
A: order_status The data type is not correct;
B: The default value is defined DEFAULT 'Default value'
C: a table of no OR REPLACE clauses;
D: with the BC;
F.: Date_ordered data type is not correct;

5. In order to successfully query view, what is required of the following options ()

A: base table must have data.
B: You need to have SELECT privileges on the view.
C: underlying table must be in the same mode.
D: You only need to have SELECT privilege on the underlying table.

Answers: B

6. Regarding the database language of the following options followed by DDL, DML, DCL, TCL is ()

A:CREATE、INSERT、COMMIT、GRANT
B:ALTER、GRANT、SAVEPOINT、UPDATE
C:DROP、DELETE、REVOKE、ROLLBACK
D:TRUNCATE、UPDATE、REVOKE、COMMIT
E:COMMENT、SELECT、REVOKE、RENAME

Reference answer: D

Analytical:
the SQL language is divided into four categories: data query language DQL, data manipulation language DML, data definition language DDL, Data Control Language DCL.

1, data query language DQL
data query language DQL basic structure is a SELECT clause, the FROM clause, the WHERE
query block of clauses:
SELECT <Field watches>
the FROM <table or view name>
the WHERE <query>

2, data manipulation language DML
data manipulation language DML three major forms:
1) Insert: the INSERT
2) Update: the UPDATE
. 3) Delete: the DELETE

3, data definition language (DDL Data Definition): create create, alter change, truncate truncate, drop deleted

4, DCL (Data Control Language, Data Control Language):
used to grant a privilege or recover access to the database, and database manipulation to control the time and effect transactions that occur. Such as:
Grant: authorization;
REVOKE: Cancel authority;

TCL (Transaction Control Language, transaction control language):
used to manage the transaction. Such as:
COMMIT: save the completed transaction action results
SAVEPOINT: keep transaction data and status for possible rollback operation
after recovering transaction-related data to the last COMMIT operation: ROLLBACK

7. Which SQL statement defines the definition of a FOREIGN KEY constraint on the DEPTNO field in the EMP table

A:

  CREATE TABLE EMP(
  empno NUMBER(4),
  ename VARCHAR2(35),
  deptno NUMBER(7,2) NOT NULL,
  CONSTRAINT emp_deptno_fk FOREIGN KEY deptno
  REFERENCES dept deptno
  );

B:

  CREATE TABLE EMP(
  empno NUMBER(4),
  ename VARCHAR2(35),
  deptno NUMBER(7,2)
  CONSTRAINT emp_deptno_fk REFERENCES dept (deptno)
  );

C:

  CREATE TABLE EMP(
  empno NUMBER(4),
  ename VARCHAR2(35),
  deptno NUMBER(7,2) NOT NULL,
  CONSTRAINT emp_deptno_fk REFERENCES dept (deptno)
  FOREIGN KEY (deptno)
  );

D:

CREATE TABLE EMP(
  empno NUMBER(4),
  ename VARCHAR2(35),
  deptno NUMBER(7,2) FOREIGN KEY
  CONSTRAINT emp_deptno_fk REFERENCES dept (deptno)
  );

Answers: B

Analysis:
foreign key constraints can be defined in the table level, can also be defined at the column level, present title correct option B is the foreign key constraints defined in the column level, column other tables foreign key constraint association must be enclosed in parentheses;

Second, multiple-choice questions

1. The following options which are one-way function property ()
A: not nest
B: each of the data manipulation
C: acting on each row returned
D: returns a result for each row
E: takes a single argument, and returns a value only
F: accept the argument may be a column or expression

Answers: BCDF

Analytical:
A: one-way function can be nested;
E: can accept more than one line of data, each row of data and returns the processed.

2. In either case, will use an outer join query? (Please select two)

A: Table to be connected have NOT NULL column.
B: the table to join only matched data
C: column connected to a NULL value.
D: Only the data tables to be joined do not match.
E: data tables to be joined have matching and mismatched.
F: Only if the table having a primary key - foreign key relationship when

Answers: CE

Analysis:
external connection is based on a table, another table match, another table data when no matching empty value instead.

3. Check create SQL statements order table below, in the implementation of the above SQL statement, which columns will automatically create an index? (Please select two)

CREATE TABLE orders(
  SER_NO NUMBER UNIQUE,
  ORDER_ID NUMBER,
  ORDER_DATE DATE NOT NULL,
  STATUS VARCHAR2(10)
  CHECK (status IN ('CREDIT', 'CASH')),
  PROD_ID NUMBER
  REFERENCES PRODUCTS(PRODUCT_ID),
  ORD_TOTAL NUMBER,
  PRIMARY KEY (order_id, order_date)
  );

A:SER_NO
B:ORDER_ID
C:STATUS
D:PROD_ID
E:ORD_TOTAL
F:composite index on ORDER_ID and ORDER_DATE

Answers: AF

Analysis:
Database UNIQUE constraint and will automatically create an index PRIMARY KEY constraint.

4. Check Marks table table structure
Here Insert Picture Description
SUBJ1, SUBJ12, SUBJ13 are three classes of student achievement, the following options right there? (Please select two)

A:

SELECT SUM(subj1, subj2, subj3) FROM marks;

B:

SELECT SUM(subj1 + subj2 + subj3) FROM marks;

C:

SELECT SUM(subj1), SUM(subj2), SUM(subj3) FROM marks;

D:

SELECT MAX(subj1, subj2, subj3) FROM marks;

E:

SELECT MINIMUM(subj1) FROM marks;

F:

SELECT COUNT(std_id) FROM marks WHERE subj1 >= AVG(subj1);

Reference answer: BC

Analysis:
aggregate functions, also called set of functions, dealing with multiple rows of data, based on this principle to analyze the topic,
A: SUM (subj1, subj2, subj3) aggregate function contains a plurality of rows and columns, no way to deal with;
BC obviously aggregate function in multi-line transactions;
error causes the same as a and D; EMINIMUM not function group; group can not function, because the system in dealing with the first process and then select the process where Fwhere, demand option if you want to achieve, can be used Alternatively HAVING where, having performed after select.

The following table built in the statement, followed by the options in SQL statements executed, which can be performed correctly? (Choose the correct two)

CREATE TABLE STUDENT (
    stuId NUMBER(11) primary key,
    stuName nvarchar2(10),
    stuAge NUMBER(4),
    stuSex NUMBER(1) CHECK (stuSex IN(0,1))
  );

A:

INSERT INTO STUDENT (stuId,stuName,stuAge,stuSex) VALUES(1,'Rick',48,0);

B:

INSERT INTO STUDENT (stuId,stuName,stuAge,stuSex) VALUES(1,'Rick',48,0);

C:

INSERT INTO STUDENT (stuId,stuName,stuAge,stuSex) VALUES(2,'Rick',48,1);

D:

INSERT INTO STUDENT (stuId,stuName,stuAge,stuSex) VALUES(3,'Rick',48,2);

Answers: AC

Analytical:
stuId primary key constraint is the primary key constraint requirement value can not be empty (this difference unique constraints), can not be repeated; B error
stuSex check constraint is required only take values of 0 and stuSex 1. D wrong

6. The following SQL statement is correct? (Please select two)
A: describle view_name;
B: describle table_name;
C: describle column_name;
D: describle sequence_name;

Reference answer: AB

Analytical:
describle only show up table or view structure

Third, the short answer

1. Please describe what you have ways to improve the efficiency of SQL execution?
Sql master key factors affecting performance:
1, reusable SQL analysis result (SGA buffer) - so use dynamic query and ensure follow the same writing format, including the principle of consistent capitalization, spaces, location, and other table alias
2, FROM resolution table from right to left - so the least number of records as a basis for the table table (on the far right)
3, ORACLE uses a bottom-up parsing WHERE clause order - so the screening will write in the most aggressive conditions Finally
4, maximizing the use of the index:
with iN will enable the full table scan, use EXISTS will use the index
with NOT iN will enable the full table scan, using the NOT
EXISTS will use the index
replacing DISTINCT with EXISTS
table connected to replace EXISTS
to avoid in the index column the use of the NOT NULL IS NULL and the IS
. 5, the Where precedence having, as soon as the original data set may be defined

2. Introduction to database transactions four properties.
Transaction atomicity (Atomicity) refers to a transaction either all executed or not executed a transaction that is not possible to perform only half stopped For example, you withdraw money from a cash machine, the transaction can be divided into two steps: 1 draw card, 2 money. impossible to draw a card, but the money did not come out. these two steps must be completed at the same time. or it does not complete.

Transactional consistency (Consistency) refers to the operation does not change the consistency of the transaction data in the database. For example, the integrity constraint a + b = 10, a transaction changing a, then b should be changed.

Independence (Isolation): independence of the transaction is also known as isolation, refers to two or more staggered state of affairs will not be executed as this may result in inconsistent data.

Persistent (Durability): Persistence refers to transactions after the transaction is successful, the firm changes made to the database is stored in the persistent database, not for no reason rollback.

Published 35 original articles · won praise 24 · views 60000 +

Guess you like

Origin blog.csdn.net/thumbs_up_sign_ygj/article/details/105015667