DB Session 4 Slides
DB Session 4 Slides
Chapter 6
Structured Query Language
Objectives
Identify the various SQL commands
Introduction
We have several DBMS and these are broadly categorized into two
Introduction
Most common DBMS are as follows, most of the sql code you will learn in
this module will work with any DBMS, in this module we will be using
MySQL, wich is the nost popular DBMS in the world
Introduction
.
SQL data types
.
SQL create command
Alter command is used alter the table structure such as the following
Add column to existing table
Rename any existing column
Change data type of any column or modify its size
Drop a column from a table
Syntax
ALTER TABLE tablename ADD(address VARCHAR(100));
Using our example
ALTER TABLE modules ADD(address VARCHAR(200));
We put comments in SQL using #
SQL alter command
SQL alter command
SQL SERVER
ALTER TABLE table_name
ALTER COLUMN column_name datatype;
MY SQL
ALTER TABLE table_name
MODIFY COLUMN column_name datatype;
SQL alter command
SQL alter command
SQL alter command
Renaming a column
Used to rename an existing column
We want to rename the address column to location
ALTER TABLE modules CHANGE address location VARCHAR(500);
SQL alter command
Renaming a column
SQL alter command
Drop a column
The drop command can be used to remove columns from the table.
Here we want to remove the location column from our table
ALTER TABLE modules DROP location;
So the location column will be removed from the modules table.
Truncate command command
The truncate command removes all the records from the table but
however, the table structure will still remain in place
The command is simple
TRUNCATE TABLE modules;