2 Using DDL Statements to Create and Manage Tables

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/43

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

44 Terms

1
New cards

Which database objects are schema objects in Oracle?

Tables, Views, Indexes, Sequences, and Private Synonyms, Constraints.

2
New cards

Which statement is correct? CREATE PUBLIC SYNONYM or CREATE PRIVATE SYNONYM

CREATE PUBLIC SYNONYM. For private the public word is omitted, just CREATE SYNONYM.

3
New cards

Can a user account own another user account or itself?

No, therefore it’s a nonschema object. The same stands for all nonschema objects. A user cannot own them.

4
New cards

Which database objects are nonschema objects in Oracle?

Users, Roles, and Public Synonyms.

5
New cards

What is a schema in Oracle?

A schema is a logical collection of database objects such as tables, indexes, views, and others owned by a user account. It has the same name as the user account.

6
New cards

What is the difference between a schema and a user account?

A user account is the owner identified by username with privileges; a schema is the set of objects owned by that account.

7
New cards

Can there be more accounts than users?

One user will often have one account and therefore one schema. But the opposite isn’t true, there can be more accounts than users.

8
New cards

What is the basic syntax to create a table in Oracle?

CREATE TABLE tablename ( columnname datatype [constraints], … );

9
New cards

What are the key parts of a CREATE TABLE statement?

Reserved words CREATE TABLE, the table name, column definitions (name, datatype, constraints), separated by commas.

10
New cards

What happens if you try to create a table that already exists in the schema?

The CREATE TABLE statement will fail with an error.

11
New cards

What are the naming rules for Oracle database objects?

Names must be 1–30 characters, start with a letter, may include letters, digits, $, _, #, not case-sensitive, and cannot use reserved SQL words.

12
New cards

What are quoted names in Oracle?

Names enclosed in double quotes, case-sensitive, can start with any character, include spaces or reserved words. Must always be referenced with quotes.

13
New cards

What is a namespace in Oracle database?

A logical boundary grouping objects. Objects in the same namespace must have unique names; objects in different namespaces can share names.

14
New cards

What command is used to review the structure of a table in Oracle?

DESC table_name (a SQL*Plus command, not standard SQL).

15
New cards

What does the DESC command display?

It shows column names, NOT NULL constraints, and data types of the table.

16
New cards

What are the main categories of Oracle data types?

Character, Numeric, Date/Time, and Large Objects (LOBs).

17
New cards

What is the difference between CHAR(n) and VARCHAR2(n)?

CHAR(n) is fixed length and pads with blanks; VARCHAR2(n) is variable length and does not pad. CHAR max 2000, VARCHAR2 max 4000 (or 32767 with EXTENDED).

18
New cards

What are the precision and scale in NUMBER(n,m)?

Precision n = total number of digits. Scale m = number of digits right of decimal. Defaults: both max if omitted. m can be –84 to 127.

19
New cards

What does DATE datatype store in Oracle?

Year, Month, Day, Hour, Minute, Second.

20
New cards

What is the default Oracle DATE format?

DD-MON-RR, controlled by NLSDATEFORMAT or NLS_TERRITORY.

21
New cards

What is the TIMESTAMP(n) datatype?

It extends DATE with fractional seconds (n=0–9, default 6).

22
New cards

What is the TIMESTAMP WITH TIME ZONE datatype?

A TIMESTAMP that stores time zone region or offset.

23
New cards

What is TIMESTAMP WITH LOCAL TIME ZONE?

Stores time without offset; displayed in user’s local session timezone.

24
New cards

What are INTERVAL data types?

INTERVAL YEAR(n) TO MONTH and INTERVAL DAY(n1) TO SECOND(n2). Used for representing spans of time.

25
New cards

What are Oracle LOB types?

BLOB for binary large objects, CLOB for character large objects, NCLOB for Unicode text. Cannot be used in primary keys, DISTINCT, GROUP BY, ORDER BY, or joins.

26
New cards

What are the five types of constraints in Oracle?

NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK.

27
New cards

What is a NOT NULL constraint?

Ensures a column must always have a value. By default, columns allow NULL.

28
New cards

What is a UNIQUE constraint?

Ensures all values in a column (or group of columns) are unique. Allows NULLs.

29
New cards

What is a PRIMARY KEY constraint?

Combination of NOT NULL and UNIQUE. A table may have only one PRIMARY KEY. It may be single-column or composite.

30
New cards

What is a FOREIGN KEY constraint?

Enforces referential integrity by requiring values in child table columns to exist in parent table’s PRIMARY KEY or UNIQUE columns.

31
New cards

What is ON DELETE CASCADE in FOREIGN KEY constraints?

When parent rows are deleted, child rows referencing them are also deleted.

32
New cards

What is ON DELETE SET NULL in FOREIGN KEY constraints?

When parent rows are deleted, child table’s foreign key column values are set to NULL.

33
New cards

What is a CHECK constraint?

Allows only rows that satisfy a Boolean condition expression. Cannot use subqueries, NEXTVAL, CURRVAL, SYSDATE, etc.

34
New cards

Can NOT NULL be defined out-of-line in Oracle?

No. NOT NULL can only be defined inline or via ALTER TABLE column modification.

35
New cards

What happens when you drop a column in Oracle?

The column and its data, constraints, and indexes are permanently removed.

36
New cards

What keywords are used to drop a column that is referenced by a foreign key constraint?

CASCADE CONSTRAINTS.

37
New cards

Can you drop all columns from a table in Oracle?

No. A table must always have at least one column.

38
New cards

What is the effect of setting a column UNUSED?

It becomes permanently unavailable but not physically dropped. Still counts toward 1000 column limit until dropped later.

39
New cards

What is an external table in Oracle?

A read-only table defined in the database but whose data resides outside the database.

40
New cards

What restrictions apply to external tables?

Cannot have LOB columns, cannot have constraints, cannot update/insert/delete rows, cannot set columns UNUSED.

41
New cards

What is the purpose of a DIRECTORY object in Oracle?

Maps a name in the database to a path in the server’s file system for external tables.

42
New cards

Which Oracle utilities are used with external tables?

SQL*Loader and Oracle Data Pump.

43
New cards

What does TRUNCATE TABLE do in Oracle?

Removes all rows from a table quickly without firing DML triggers. It is DDL, auto-commits, and cannot be rolled back.

44
New cards

What happens if TRUNCATE TABLE is applied to a parent table with ON DELETE CASCADE child rows?

It raises an error unless TRUNCATE TABLE … CASCADE is used.