Creating tables and loading data Flashcards

(89 cards)

1
Q

What are SQL statements used for?

A

Interacting with tables, columns, and rows in relational databases

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

What are the two main categories of SQL statements?

A

Data Definition Language (DDL) and Data Manipulation Language (DML)

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

What does DDL stand for?

A

Data Definition Language

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

What does DML stand for?

A

Data Manipulation Language

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

What are DDL statements used for?

A

Defining, changing, or deleting database objects like tables

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

Name four common DDL statements

A

CREATE, ALTER, TRUNCATE, DROP

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

What does CREATE do in SQL?

A

Creates tables and defines columns

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

What does ALTER do in SQL?

A

Modifies table structure (add/drop columns, change data types)

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

What does TRUNCATE do in SQL?

A

Deletes all data in a table but keeps the table structure

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

What does DROP do in SQL?

A

Deletes a table completely

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

What are DML statements used for?

A

Reading and modifying data in tables

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

What does CRUD stand for?

A

Create, Read, Update, Delete

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

Name four common DML statements

A

INSERT, SELECT, UPDATE, DELETE

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

What does INSERT do?

A

Adds new rows to a table

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

What does SELECT do?

A

Retrieves data from a table

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

What does UPDATE do?

A

Modifies existing rows in a table

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

What does DELETE do?

A

Removes rows from a table

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

Which category does CREATE belong to?

A

DDL

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

Which category does INSERT belong to?

A

DML

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

Which category does DROP belong to?

A

DDL

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

Which category does SELECT belong to?

A

DML

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

What is the key difference between DDL and DML?

A

DDL changes structure; DML changes data

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

What are key considerations before creating a table?

A

Choose schema, define table name, define column names and data types, decide on NULLs and duplicates, reference ERD

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

Why are schemas important when creating tables?

A

They logically organize database objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What information is needed before creating a table?
Table name, column names, data types, constraints
26
What tool helps design tables before creation?
Entity Relationship Diagram (ERD)
27
What are three common methods for creating tables?
UI tools, SQL statements, APIs
28
Which SQL statement is used to create a table?
CREATE TABLE
29
When is using a UI tool for table creation useful?
For small-scale or occasional tasks
30
Give an example of a Db2 UI tool
Db2 on Cloud console
31
Give an example of a MySQL UI tool
phpMyAdmin
32
Give an example of a PostgreSQL UI tool
pgAdmin
33
Why use SQL scripts for table creation?
To automate creation of multiple tables
34
What do administrative APIs allow?
Programmatic creation and management of tables
35
What is the first step in creating a table in Db2 on Cloud?
Select a schema
36
What is the default schema in Db2?
The username
37
What is a fully qualified table name?
SchemaName.TableName
38
What must you define when adding a column?
Name, data type, NULL setting, length/scale
39
What action finalizes table creation in Db2 on Cloud?
Click Create
40
Can a table structure be modified after creation?
Yes
41
Which SQL command modifies a table structure?
ALTER TABLE
42
What does DROP TABLE do?
Deletes the table
43
What can you modify after table creation?
Add columns, set constraints, alter structure
44
What are post-creation actions available?
Drop table, generate SQL, modify structure, explore dependencies
45
What does NULL setting determine?
Whether a column can store empty values
46
Why confirm all table details before creation?
To avoid later structural issues
47
What type of SQL statement is CREATE TABLE?
Data Definition Language (DDL)
48
What is the purpose of CREATE TABLE?
To create a new table in a database
49
What comes immediately after CREATE TABLE in the syntax?
The table name
50
Where are column definitions written in CREATE TABLE?
Inside parentheses ()
51
How are column definitions separated?
With commas
52
What must each column definition include?
Column name and data type
53
What optional constraints can be added to columns?
PRIMARY KEY, NOT NULL, etc.
54
What does PRIMARY KEY ensure?
Uniqueness and no duplicate values
55
What does NOT NULL ensure?
The column cannot contain NULL values
56
What is the difference between CHAR and VARCHAR?
CHAR is fixed length; VARCHAR is variable length
57
In CREATE TABLE provinces, what does CHAR(2) mean?
A fixed-length string of 2 characters
58
In CREATE TABLE provinces, what does VARCHAR(24) mean?
A variable-length string up to 24 characters
59
What is a primary key?
A column that uniquely identifies each row
60
Why is Author_ID defined as PRIMARY KEY?
To prevent duplicate author records
61
Why are Firstname and Lastname marked NOT NULL?
Because an author must have a name
62
What is a fully defined CREATE TABLE statement made up of?
Table name, column names, data types, constraints
63
What happens if you issue a CREATE TABLE statement?
A new table is created in the database
64
In the Author example, which column is the primary key?
Author_ID
65
What constraint prevents duplicate values?
PRIMARY KEY
66
What constraint prevents empty values?
NOT NULL
67
What type of SQL statements are ALTER, DROP, and TRUNCATE?
Data Definition Language (DDL)
68
What is ALTER TABLE used for?
To modify the structure of an existing table
69
Can ALTER TABLE add columns?
Yes
70
Can ALTER TABLE remove columns?
Yes
71
Can ALTER TABLE change data types?
Yes
72
Does ALTER TABLE use parentheses like CREATE TABLE?
No
73
How do you add a column using ALTER TABLE?
ALTER TABLE table_name ADD COLUMN column_name datatype
74
How do you modify a column data type?
ALTER TABLE table_name ALTER COLUMN column_name SET DATA TYPE datatype
75
How do you remove a column from a table?
ALTER TABLE table_name DROP COLUMN column_name
76
What does BIGINT store?
Large integers up to 19 digits
77
What problem can occur when changing a column’s data type?
Existing data may not match the new type
78
What happens if existing data is incompatible with a new data type?
The ALTER statement fails with an error
79
What does DROP TABLE do?
Deletes a table and all its data
80
What is the syntax for DROP TABLE?
DROP TABLE table_name
81
What happens to data when DROP TABLE is executed?
Data is deleted with the table
82
What does TRUNCATE TABLE do?
Deletes all rows in a table but keeps the table structure
83
What is the syntax for TRUNCATE TABLE?
TRUNCATE TABLE table_name IMMEDIATE
84
What does IMMEDIATE mean in TRUNCATE?
The action is processed immediately and cannot be reversed
85
Is TRUNCATE faster than DELETE without WHERE?
Yes
86
What is the difference between DROP TABLE and TRUNCATE TABLE?
DROP removes the table; TRUNCATE removes only data
87
Which statement changes table structure?
ALTER TABLE
88
Which statement removes a table completely?
DROP TABLE
89
Which statement removes all rows but keeps the table?
TRUNCATE TABLE