PowerPoint 2 Flashcards

1
Q

What are the different SQL Categories/Languages?

A
  1. Data Definition Language(DDL)
  2. Data Manipulation Language(DML)
  3. Data Retrieval Language(DRL)
  4. Transaction Control(TCL)
  5. Data Control Language(DCL)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain what DDL is

A

Data Definition Language consists of the SQL commands that can be used to define the database schema.

DDL is a set of SQL commands used to CREATE, MODIFY, and DELETE database structures but not data.

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

What are the most commonly used DDL commands?

A
  1. CREATE
  2. DROP
  3. ALTER
  4. TRUNCATE
  5. COMMENT
  6. RENAME
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is CREATE used for?

A

CREATE is used to create the database or its objects.

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

What is DROP used for?

A

This command is used to delete objects from a database.

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

What is ALTER used for?

A

ALTER is used to alter the structure of the database.

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

What is TRUNCATE used for?

A

The TRUNCATE TABLE command deletes the data inside a table, but not the table itself.

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

What is COMMENT used for?

A

COMMENT is used to add comments to the data directory.

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

What is RENAME used for?

A

This is used to rename an object existing in the database.

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

What will this do?

USE <database_name></database_name>

A

In order to tell MySQL on which database will be working, you need to select the database.

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

What will this do?

CREATE DATABASE <database_name></database_name>

A

This will create a new database with the name specified.

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

What will this do?

CREATE TABLE <table_name> (</table_name>

<column1> datatype,
<column2> datatype,
<column3> datatype,
...
);
</column3></column2></column1>

A

The CREATE TABLE statement is used to create a new table in a database.

The column parameters specify the names of the columns of the table.

The datatype parameter specifies the type of data the column can hold.

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

What is the ALTER TABLE statement used for?

A

The ALTER TABLE statement is used to ADD, DELETE, or MODIFY columns in an existing table.

The ALTER TABLE statement is also used to ADD and DROP various constraints on an existing table.

Examples:
- ALTER TABLE <table_name> ADD <column_name> datatype;
- ALTER TABLE <table_name> DROP COLUMN <column_name>;
- ALTER TABLE <table_name>
MODIFY COLUMN <column_name> datatype;</column_name></table_name></column_name></table_name></column_name></table_name>

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

What will this do?

DROP TABLE <table_name>;</table_name>

A

The DROP TABLE statement is used to drop an existing table in a database.

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

What is a Datatype and what are the three kind of datatypes?

A

A data type is a classification that specifies which type of value a variable has and what type of mathematical, relational or logical operations can be applied to it without causing an error.

The three datatypes are:
1. String datatypes(varchar, char, etc.)
2. Numeric datatypes(int, float, double, dec, etc.)
3. Date and Time Datatypes(date, datetime, timestamp etc.)

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

What are Constraints?

A

SQL constraints are used to specify rules for the data in a table.

Constraints are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the table.

17
Q

What is the NOT NULL Constraint?

A

Ensures that a column cannot have a NULL value.

18
Q

What is the UNIQUE Constraint?

A

Ensures that all values in a column are different.

19
Q

What is the PRIMARY KEY Constraint?

A

A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table.

A table can have only ONE primary key; and in the table, the primary key can consist of single or multiple columns(fields).

20
Q

What is the FOREIGN KEY Constraint?

A

The FOREIGN KEY is a field that
Prevents actions that would destroy links between tables.

21
Q

What is the CHECK Constraint?

A

Ensures that the values in a column satisfies a specific condition.

22
Q

What is the DEFAULT Constraint?

A

Sets a default value for a column if no value is specified.

23
Q

What is the AUTO_INCREMENT Constraint?

A

This constraint automatically generates a unique number whenever we insert a new record into the table.
Generally, we use this constraint for the primary key field in a table.

24
Q

What’s the difference between PRIMARY KEY and UNIQUE?

A

A table can have only one PRIMARY KEY constraint, but multiple UNIQUE constraints.

25
Q

What are the ways you can add a Constraint to a table?

A
  1. Inline method
  2. Out-of-line method
26
Q

What are the inline and out-of-line way of adding the primary key constraint to a table?

A

inline way:
CREATE TABLE <table_name> (</table_name>

<column_name> datatype,
....
....
,
PRIMARY KEY(<column_name(s)>)
);

out-of-line way:
ALTER TABLE <table_name>
ADD PRIMARY KEY (<column_name(s)>);
</table_name></column_name>

27
Q

What are the inline and out-of-line way of adding the foreign key constraint to a table?

A

inline way:
CREATE TABLE <table_name> (</table_name>

<column_name> datatype,
....
....
,
FOREIGN KEY (<table_name>)
REFERENCES <table_name>(<column_name>)
);

out-of-line way:
ALTER TABLE <table_name>
ADD FOREIGN KEY (<column_name(s)>)
REFERENCES <table_name>(<column_name>);
</column_name></table_name></table_name></column_name></table_name></table_name></column_name>

28
Q

What are the inline and out-of-line way of adding the UNIQUE constraint to a table?

A

inline way:
CREATE TABLE <table_name> (</table_name>

<column_name> datatype UNIQUE,
....
....
);

out-of-line way:
ALTER TABLE <table_name>
ADD CONSTRAINT <constraint_name>
UNIQUE (<column_name(s)>);
</constraint_name></table_name></column_name>

29
Q

What are the inline and out-of-line way of adding the NOT NULL constraint to a table?

A

inline way:
CREATE TABLE <table_name> (</table_name>

<column_name> datatype NOT NULL,
....
....
);

out-of-line way:
ALTER TABLE <table_name>
MODIFY <column_name(s)> datatype NOT NULL;
</table_name></column_name>

30
Q

What are the inline and out-of-line way of adding the CHECK constraint to a table?

A

inline way:
CREATE TABLE <table_name> (</table_name>

<column_name> datatype,
....
....
,
CONSTRAINT <constraint_name>
CHECK (<column_name> = something)
);

out-of-line way:
ALTER TABLE <table_name>
ADD CONSTRAINT <constraint_name>
CHECK (<column_name> = something);
</column_name></constraint_name></table_name></column_name></constraint_name></column_name>

31
Q

What are the inline and out-of-line way of adding the DEFAULT constraint to a table?

A

inline way:
CREATE TABLE <table_name> (</table_name>

<column_name> datatype DEFAULT something,
....
....
);

out-of-line way:
ALTER TABLE <table_name>
ALTER <column_name> SET DEFAULT something;
</column_name></table_name></column_name>

32
Q

What is the inline way of adding the AUTO_INCREMENT constraint to a table?

A

inline way:
CREATE TABLE <table_name>(</table_name>

<column_name> datatype AUTO_INCREMENT PRIMARY KEY,
....
....
);
</column_name>