SQL CREATE TABLE

Tables are the basic structure where data is stored in the database. Given that in most cases, there is no way for the database vendor to know ahead of time…

SQL CREATE VIEW

Views can be considered as virtual tables. Generally speaking, a table has a set of definition that sets the structure of the table, and physically stores the data. A view…

SQL CREATE INDEX

Indexes help us retrieve data from tables quicker. Let’s use an example to illustrate this point: Say we are interested in reading about how to grow peppers in a gardening…

SQL ALTER TABLE

Once a table is created in the database, there are many occasions where one may wish to change the structure of the table. Typical cases include the following: Add a…

SQL PRIMARY KEY

A primary key is used to unique identify each row on a table. It can either be part of the actual record itself , or it can be an artificial…

SQL FOREIGN KEY

A foreign key is a field (or fields) that points to the primary key of another table. The purpose of the foreign key is to ensure referential integrity of the…

SQL DROP TABLE

Sometimes we may decide that we need to get rid of a table in the database for some reason. In fact, it would be problematic if we cannot do so…

SQL TRUNCATE TABLE

Sometimes we wish to get rid of all the data in a table. One way of doing this is with DROP TABLE, which we saw in the last section. But what if…