SQL Table Management Video
SQL Tutorial Videos >
Table Management Video
This video discusses how to manage tables in a relational database. The commands covered are CREATE TABLE, DROP TABLE, and TRUNCATE TABLE. After you finish watching this video, you'll be able to perform basic table management in a relational database.
Embed this video using the code below
In this tutorial, we look at how to use SQL to manage database tables. Before we dive into the specific commands, let us first go through the basics of a relational database.
In a relational database, data is stored in tables. Each table has a table name. A table consists of columns and rows. Each column is a field in a record, and there is a column name associated with each column. Each row represents one record. Usually when we say how many records we have, we are referring to the number of rows. With this information, now we are ready to look at how to use SQL to manage database tables.
The first thing we need to do before we can store any data in a relational database is to create a table that can store data. The SQL command for this is CREATE TABLE. The syntax for CREATE TABLE is
CREATE TABLE "table_name"
Different databases have different data types. But by and large, the common data types are numeric, character string, date/datetime, and binary.
For example, if we issue the following SQL command,
CREATE TABLE USER_TABLE
we will have created a table in the database called USER_TABLE, which has two columns: Last_Name and First_Name, both being 20 characters long. Upon creation, this table holds no data.
In order to manage the database effectively, we will also need to have the ability to remove tables from a database. The SQL statement to do this is DROP TABLE. The syntax for DROP TABLE is simply
DROP TABLE "table_name";
Dropping a table removes the table from the database. All data stored in that table is also gone.
To remove the table we had created, we issue the following SQL statement:
DROP TABLE USER_TABLE;
Sometimes we will only want to remove the data from a table, while keeping the table structure. The SQL command for this is TRUNCATE TABLE. The syntax for TRUNCATE TABLE is
TRUNCATE TABLE "table_name";
Once this command is executed, the table will be empty. The table itself still exists in the database and can be used if needed.
To truncate the table we had created, we issue the following SQL statement:
TRUNCATE TABLE USER_TABLE;
List of SQL Video Tutorials