Lesson 2: SQL Data Definition Language

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/28

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 12:34 PM on 8/12/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

29 Terms

1
New cards

What is the main purpose of Data Definition Language (DDL) in MySQL?

To create, delete, and modify database structures.

2
New cards

What are the three main DDL statements discussed in the notes?

CREATE, DROP, and ALTER.

3
New cards

Which statement would you use to create a new database?

CREATE DATABASE.

4
New cards

Which statement permanently deletes an existing database?

DROP DATABASE.

5
New cards

What does CREATE TABLE do?

Creates a new table and defines its columns and data types.

6
New cards

What happens when you use DROP TABLE?

The table and all its data are deleted.

7
New cards

When would you use ALTER TABLE?

When you need to modify the structure of an existing table.

8
New cards

What three common structural changes can ALTER TABLE perform?

ADD a column, MODIFY a column, or DROP a column.

9
New cards

Which statement would you use to add a new column to an existing table?

ALTER TABLE … ADD.

10
New cards

Which statement would you use to change a column's data type?

ALTER TABLE … MODIFY.

11
New cards

Which statement would you use to remove a column from a table?

ALTER TABLE … DROP.

12
New cards

What is the purpose of constraints in a database table?

To maintain data accuracy and integrity.

13
New cards

What does the NOT NULL constraint prevent?

It prevents a column from containing NULL values.

14
New cards

What does the UNIQUE constraint ensure?

It prevents duplicate values in a column or group of columns.

15
New cards

What is a PRIMARY KEY used for?

To uniquely identify each record in a table.

16
New cards

What two properties does a PRIMARY KEY combine?

NOT NULL and UNIQUE.

17
New cards

What is the purpose of a FOREIGN KEY?

To link tables and enforce referential integrity.

18
New cards

If tblReceipt.itemId refers to tblItems.itemId, what type of key is tblReceipt.itemId?

A FOREIGN KEY.

19
New cards

What does AUTO_INCREMENT do?

Automatically generates sequential numbers, commonly for primary keys.

20
New cards

Which constraint would you use if every item must have a name?

NOT NULL.

21
New cards

Which constraint would you use to prevent two records from having the same value?

UNIQUE.

22
New cards

Which constraint would you use to give every record a unique identifier?

PRIMARY KEY.

23
New cards

Which constraint would you use to establish a relationship between two tables?

FOREIGN KEY.

24
New cards

Which feature would you use to automatically assign sequential IDs to new records?

AUTO_INCREMENT.

25
New cards

What is the difference between UNIQUE and PRIMARY KEY?

UNIQUE prevents duplicates; PRIMARY KEY uniquely identifies records and is both NOT NULL and UNIQUE.

26
New cards

What is the difference between a PRIMARY KEY and a FOREIGN KEY?

A primary key identifies records in its own table; a foreign key links to a key in another table.

27
New cards

What is the difference between DROP and ALTER?

DROP removes a database, table, or column, while ALTER changes an existing table's structure.

28
New cards

In the example, why is itemId in tblReceipt a foreign key?

It references itemId in tblItems, creating a relationship between the tables.

29
New cards

Why is itemId in tblItems a good candidate for PRIMARY KEY AUTO_INCREMENT?

It uniquely identifies each item and can be automatically numbered.