Section 3 - Creating Databases and Tables Flashcards

1
Q

Can you have more than one database on the same database server? (YES / NO)

A

YES

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

What is the naming convention for when and when not to use CAPITAL letters?

A
  • Use UPPERCASE for SQL commands
  • Use lowercase for custom names

For example, “CREATE DATABASE augiesdatabase”

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

What is the command for deleting a database?

A

DROP DATABASE ;

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

Write a command for deleting a database named useless_database.

A

DROP DATABASE useless_database;

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

Broadly-speaking, what is a database composed of? (At least, a what is a relational database composed of?)

A

A bunch of tables.

These tables contain data.

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

What is a table?

A

A table holds the data.

Specifically, a table is a collection of related data held in a structured format within a database.

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

A database is structured via ________s and ________s.

A

A database is structured via COLUMNs and ROWs.

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

What is a column in a database?

A

Think of a column like a “Header” or category.

For example, first_name, age, last_name, major, relatives, hobbies might all be columns.

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

What is a ROW in a table composed of?

A

A ROW contains the actual data in the tables.

For example, if we have a column named, “first_name”, the corresponding row might contain data like, “Adam”, “Adrian”, “Penelope”, “Vivian”, “Gina”, “Cooper”, etc.

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

Most Databases are Composed of Lots and Lots of Tables: TRUE or FALSE

A

TRUE

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

What is a Data Type?

Give two examples.

A

A data type is a structured data format by which we can input/aggregate similar data.

For example, VARCHAR is a text data type, whereas INT (integer) is a number data type.

If we had a column of people’s ages, we would definitely want this to be an INT data type, because age is never (or very rarely should be) a text field.

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

Give one example where data type could be helpful.

A

You have an age column for keeping track of your employees health insurance.

Keeping the column as an INT is helpful. If you could type any type of text, it’d be much more difficult to read and manipulate the data.

For example, people could list their age as “Twenty-seven”, “Twenty seven”, “27”, “twenty 7” or whatever else if you did not restrict your data type to INT.

As you can see, that would get confusing real fast!

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

What is a STRING data type?

A

STRING data types are data types involving letters/text. (As opposed to Numeric data types, which involve numbers.)

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

What is a NUMERIC data type?

A

NUMERIC data types involve numbers. (As opposed to text / letters.)

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

WHAT IS a DATE data type?

A

A DATE data type involves various DATE/Calendar/day of year formats. This is different and more specific than the numerica

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

How many of the data types will you use? Should you memorize them?

A

You’ll likely only need to use a small subset of the huge variety of datatypes. DON’T memorize them.

17
Q

What type of data is a VARCHAR?

A

VARCHAR is a text data type. The VAR part of VARCHAR means that it a variable length. (As opposed to a set length.)

18
Q

What does VARCHAR stand for?

A

VARCHAR stands for Variable Character, which means that the character length is variable.
This means you can input character “strings” of different lengths.

19
Q

What is the basic syntax for creating a table?

A

CREATE TABLE tablename
(
column_name DATA_TYPE,
column_name DATA_TYPE
)

20
Q
Write syntax for the following:
      - Create a table
      - Name the table my_first_table
      - Create a text column named 
        column_1, which should be variable 
        characters up to 100 characters in 
        length.
     - Create an integer column named 
       column_2
A
CREATE TABLE my_first_table
          (
                    column_1 VARCHAR(100),
                    column_2 INT
           );
21
Q

Naming Conventions:

Should table names be singular, plural, or either?

A

PLURAL

22
Q

What is the command for selecting and working out of a particular database?

A

USE ;

23
Q

What is the USE command used for?

A

It is USEd for selecting and working within a particular database.

24
Q

What is the command for displaying the names of all the tables in the currently-selected database?

A

SHOW TABLES;

25
Q

What does the SHOW TABLES command do?

A

This returns the names of all the tables in the associated database.

26
Q

What is the command for displaying all the columns in a given table?

A

SHOW COLUMNS FROM ;

27
Q

What does the SHOW COLUMNS command do?

A

This displays all the columns within a given table.

28
Q

Write a command for displaying all the columns from a table name named bora_bora.

A

SHOW COLUMNS FROM bora_bora;

29
Q

What does the DESC command do?

A

This returns the details of all the columns within a table.

30
Q

What does the DROP TABLE command do?

A

This deletes the table and it’s contents.

31
Q

What is the command for deleting a table and its contents?

A

DROP TABLE ;

32
Q

Write a command for deleting a table named sodas.

A

DROP TABLE sodas;

33
Q

If you created a table, then dropped it (deleted it), then wrote a command to DESC the table, what would happen? Why?

A
  • You would return an error.

- Why? Because the table no longer exists.

34
Q

Exercise:

  • Create a pastries table.
  • It should have two columns, one called name, one called quantity.
  • Name should have 50 characters max.
  • Quantity should be an integer.
A

CREATE TABLE pastries(
name VARCHAR(50),
quantity INT
)