Lab 03 - SQL (DDL)
Lab 03 - SQL (DDL)
• Simple Example:
CREATE TABLE Persons (
PersonID number(9,0),
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
SQL DROP TABLE Statement
• The DROP TABLE statement is used to drop an
existing table in a database.
– Ex
• ALTER TABLE customers DROP
customer_name;
Alter / Add Column
– ALTER TABLE table_name ADD
column_name column_definition;
• UNIQUE :
– Ensures that all values in a column are different
• PRIMARY KEY :
– A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table
• FOREIGN KEY :
– Uniquely identifies a row/record in another table
• CHECK :
– Ensures that all values in a column satisfies a specific condition
• DEFAULT :
– Sets a default value for a column when no value is specified
• INDEX :
– Used to create and retrieve data from the database very quickly
NOT NULL
• By default, a column can hold NULL values.
• The NOT NULL constraint enforces a column to NOT accept NULL values.
• This enforces a field to always contain a value, which means that you
cannot insert a new record, or update a record without adding a value
to this field.
• Both the UNIQUE and PRIMARY KEY constraints provide a guarantee for
uniqueness for a column or set of columns.
• However, you can have many UNIQUE constraints per table, but only one
PRIMARY KEY constraint per table.