157A Clauses Flashcards
SQL Create
CREATE DATABSE database_name;
SQL USE
USE database_name;
SQL DROP
DROP DATABASE database_name;
SQL CREATE TABLE
In an SQL driven database, the data is stored in a structured manner, i.e. in the form of tables.
CREATE TABLE table_name(
column1 dataype,
column2 datatype,
column3 datatype);
SQL DESC
Every table in a database has a structure of its own. To display the structure of database tables, we
use the DESC statements.
DESC table_name;
SQL INSERT INTO
The SQL INSERT INTO Statement is used to insert data into database tables.
INSERT INTO database_name(column1, column2, column3) VALUES (data,data,data);
SQL SELECT
In order to retrieve the result-sets of the stored data from a database table, we use the SELECT
statement.
SELECT * FROM database_name;
or
SELECT column1, column2,column3 FROM table_name;
SQL UPDATE
When the stored data in a database table is outdated and needs to be updated without having to
delete the table, we use the UPDATE statement
UPDATE database_name SET column1 = value1, column2, value2;
SQL DELETE
DELETE FROM table_name WHERE (CONDITION)
SQL DROP TABLE
DROP TABLE table_name;
SQL TRUNCATE TABLE
The TRUNCATE TABLE statement is implemented in SQL to delete the data of the table but not the
table itself.
TRUNCATE TABLE table_name;
SQL ALTER TABLE
The ALTER TABLE statement is used to alter the structure of a table. For instance, you can add, drop,
and modify the data of a column using this statement.
ALTER TABLE table_name
{ADD|DROP|MODIFY} column_name {data_type};
SQL DISTINCT CLAUSE
The DISTINCT clause in a database is used to identify the non-duplicate data from a column.
SELECT DISTINCT column1, column2…columnN FROM table_name;
SQL WHERE CLAUSE
the WHERE clause is used to filter rows from a table by applying a condition
SELECT * FROM table_name WHERE age > 20;
SELECT column1, column2….columnN
FROM table_name
WHERE CONDITION;
SQL AND/OR Operators
The AND/OR Operators are used to apply multiple conditions in the WHERE clause.
SELECT column1, column2….columnN
FROM table_name
WHERE CONDITION-1 {AND|OR} CONDITION-2