PowerPoint 2 Flashcards
What are the different SQL Categories/Languages?
- Data Definition Language(DDL)
- Data Manipulation Language(DML)
- Data Retrieval Language(DRL)
- Transaction Control(TCL)
- Data Control Language(DCL)
Explain what DDL is
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.
What are the most commonly used DDL commands?
- CREATE
- DROP
- ALTER
- TRUNCATE
- COMMENT
- RENAME
What is CREATE used for?
CREATE is used to create the database or its objects.
What is DROP used for?
This command is used to delete objects from a database.
What is ALTER used for?
ALTER is used to alter the structure of the database.
What is TRUNCATE used for?
The TRUNCATE TABLE command deletes the data inside a table, but not the table itself.
What is COMMENT used for?
COMMENT is used to add comments to the data directory.
What is RENAME used for?
This is used to rename an object existing in the database.
What will this do?
USE <database_name></database_name>
In order to tell MySQL on which database will be working, you need to select the database.
What will this do?
CREATE DATABASE <database_name></database_name>
This will create a new database with the name specified.
What will this do?
CREATE TABLE <table_name> (</table_name>
<column1> datatype,
<column2> datatype,
<column3> datatype,
...
);
</column3></column2></column1>
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.
What is the ALTER TABLE statement used for?
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>
What will this do?
DROP TABLE <table_name>;</table_name>
The DROP TABLE statement is used to drop an existing table in a database.
What is a Datatype and what are the three kind of datatypes?
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.)