My Addition Flashcards
In refernce of ALTER TABLE statements
- What is the syntax for
ADD
?
2 As in add column ColumnName
.
- As in include
DataType
ALTER TABLE TableName ADD ColumnName DataType;
In refernce of ALTER TABLE statements
- What is the syntax for
CHANGE
? - As in change a column
CurrentColumnName
toNewColumnName
.
ALTER TABLE TableName CHANGE CurrentColumnName NewColumnName NewDataType;
In refernce of ALTER TABLE statements
- What is the syntax for
DROP
? - As in
DROP ColumnName
ALTER TABLE TableName DROP ColumnName;
What is the definition of tables in relational databases?
Tables are the core structure in relational databases containing a fixed sequence of columns and a varying set of rows.
Each column has a name and a specific data type, while each row consists of values that correspond to the column’s data types.
What are the components of a table?
- A table must have at least one column and can have multiple rows.
- A table can also be empty (having no rows).
Each column has a name and a specific data type.
How do databases handle duplicate rows?
Some databases may allow duplicate rows temporarily, particularly when loading external data into a temporary table.
What SQL statement is used to define a new table?
CREATE TABLE
This statement specifies table names and data types.
What does the DROP TABLE statement do?
Deletes a table and all its data.
What is the purpose of the ALTER TABLE statement?
Used to modify an existing table by adding, changing, or deleting columns.
List common data types used in tables.
- integers (INT)
- values with 0 to N characters (VARCHAR(N))
- dates (DATE)
- decimals (DECIMAL)
What rule governs the values in a cell of a table?
Exactly one value per cell.
Are duplicate column names allowed in a table?
No; duplicate column names are not allowed within the same table but are allowed in different tables.
What principle allows for optimization of storage in tables?
No significant row order
supporting the principle of data independence.
What does it mean that there can be no duplicate rows in a table?
No two rows in a table may have identical values across all columns.
What is a NULL value in a table?
Represents the absence of data in a cell.
- What is the SQL syntax for creating a table
TableName
? - As in with the
Column$
&Data_Type
.
CREATE TABLE TableName (Column1 DATA_TYPE, Column2 DATA_TYPE, ..., ColumnN DATA_TYPE);
Fill in the blank: The ID column is of data type _______.
Integer (INT)
What data type is used for the Name
column with a max 40 characters?
Variable-length string with maximum 40 characters (VARCHAR(40)).
What is the appropriate data type for the ProductType
column?
Variable-length string with maximum 3 characters (VARCHAR(3)).
What data type is used to store dates in a table?
Date
What is the format for the Weight
column data type?
Decimal number with six significant digits and one digit after the decimal point (DECIMAL(6,1))
.
True or False: A table can have multiple rows with identical data.
False.
Why are integers commonly used for IDs in databases?
They allow for efficient storage and quick retrieval when querying for specific products.
What is the advantage of using VARCHAR
for the Name
column?
It allows for variable-length strings, using only the necessary space for each entry.
Explain the data type DECIMAL(6,1)
.
It can accurately represent decimal numbers with up to 6 total digits, of which 1 digit is after the decimal point.
What is a data type in a database?
A data type is a named set of values from which column values in a database are derived.
What are the categories of data types?
- Integer Data Types
- Decimal Data Types
- Character Data Types
- Date and Time Data Types
- Binary Data Types
- Spatial Data Types
- Document Data Types
- Specialized Data Types
What do Integer Data Types represent?
Whole numbers, including positive and negative values.
- INT (4 bytes): A standard integer, storing a wide range of whole numbers (e.g., -2 billion to +2 billion).
- SMALLINT (2 bytes): A smaller integer with a more limited range (e.g., -32,768 to +32,767).
These are examples of?
These are examples of Integer Data Types
What are Decimal Data Types used for?
Numbers that require a fractional component.
- FLOAT
- DECIMAL
Are examples of which Data Type?
- FLOAT
- DECIMAL
These are examples of Decimal
types
What do Character Data Types store?
Text strings.
What is the difference between CHAR
and VARCHAR
?
-
CHAR
is fixed-length -
VARCHAR
is variable-length
What do Date
and Time
Data Types store?
Dates, times, or both.
What are examples of Date
and Time
Data Types?
- DATE
- TIME
- DATETIME
- TIMESTAMP
What do Binary Data Types store?
Raw binary data.
What are some examples of Binary Data Types?
- BLOB
- BINARY
- VARBINARY
What is the purpose of Spatial Data Types?
To manage geometric data like points and polygons.