Create: Create Command -Creates a table in the database.
CREATE TABLE<Table Name>
(Column_Name1 Datatype(Size),
Column_Name2 Datatype(Size)
…);
i.e.
CREATE TABLE employees
( Employee_id INTEGER PRIMARY KEY,
First_Name CHAR(20),
Last_name CHAR(25),
Dept CHAR(15));
Alter Command: Alter Table command modifies the structure of an existing Table adding or Droping the column or a constraint, e.g.,:
To Add A Column in a Table
ALTER TABLE <Table_Name>
Add Column_Name Datatype;
To Drop A Column from a Table
ALTER TABLE <Table_Name>
DROP COLUMN <Column_Name>;
Drop: Drop Table deletes an Table in the database and it cannot be rolled back.
DROP TABLE<Table_Name>;
i.e.
DROP TABLE Dept;
SQL – Select Statement Structure
Select Statement Structure:SELECT [ DISTINCT ] column_list [AS correlation_name ]
FROM <TableName>
[WHERE <conditions>]
[GROUP BY column_list ]
[HAVING search_condition ]
[ORDER BY {column_name | value} [sort_order]]
Select statement:
SELECT Column1, Column2, Column3
FROM Table1;
SQL Select All Query:
SELECT * from <TableName>;
To Select a each DISTINCT element in a Column Use Distinct option in Select
SELECT DISTINCT Column
FROM Table_Name
Select Statement with WHERE clause -Where clause includes a comparison predicate, which restricts the rows returned by the query. The WHERE clause eliminates all rows from the result that does not match the condition. Use of Where Clause in Select
SELECT *
FROM Table_Name
WHERE <Condition>;
Use of Where Clause with And/Or
SELECT *
FROM Table_Name
WHERE <Condition1>*And/Or <Condition2>;