Tables:
A RDBMS database uses tables for storing the data. A table is nothing but a
collection of data that is related to one another, in the form of rows and columns.
Rows:
A Row represents a collection of fields that end up making a record in the
database.
Column:
In a database, a column represents those values that are of the same type. A column
is also called an attribute.
What is SQL?
SQL stands for Structured Query Language. It is a programming language that is used
to request information from a database. SQL can be used to manage and share data in
a relational database management system. Moreover, users can perform actions like
insertion, deletion, selection, etc on the database.
SQL programming is widely used as using this language we can create, store as well
as manipulate the data inside the database. Moreover, SQL can be embedded within
other languages through SQL libraries and modules.
SQL Data Types:
===============
Various data types in SQL are-
Data type Description
VARCHAR(size) Variable length character data
CHAR (size) Fixed-length character data
BINARY (size) Binary byte strings
NUMBER(a,b) Variable-length numeric data
DATE Date and time values
LONG Variable-length character data up to 2 gigabytes
CLOB Character data up to 4 gigabytes
RAW Raw binary data
BLOB Binary data up to 4 gigabytes
BFILE Binary data stored that is stores in external file up to 4 gigabytes
ROWID 64 base number system for the unique address of a particular row in the table
SQL Operators:
==============
Arithmetic operators
Operator Description
+ Add values of operands
– Subtract values of operands
* Multiply operand’s values
/ Divide values of operands
% Modulus operation on operands
Comparison operators:
======================
In the table below, if condition gets satisfied then “True” Boolean value is
returned.
Operator Description
= Determine if the values of operands are equal.
!= Check if the values of operands are not equal.
> Determine if the left operand is more than the right operand.
< Check if the right operand is more than the left operand.
>= Determine if the left operand is more than or equal to the right operand.
<= Check if the right operand is more than or equal to the left operand.
!> Determine if the right operand is not more than the left operand.
!< Check if the left operand is not more than the right operand.
Logical Operators:
=================
Operator Description
OR Returns true if either operand is true. Else it returns false if both the
operands are false.
AND Returns true if both operands are true. Else it returns false if either or
both the operands are false
NOT Returns true if condition is false and returns false if the condition is
true.
SQL Commands:
==============
Create Database
===============
The CREATE DATABASE statement is used to create a fresh new SQL database. Following
is the syntax-
CREATE DATABASE database_name;
Drop Database:
===============
The DROP DATABASE query is used to drop or delete an existing SQL database. Syntax-
DROP DATABASE database_name;
Rename Database:
=================
The RENAME DATABASE query is used to rename an existing database. Following is the
syntax-
RENAME DATABASE old_database_name TO new_database_name;
Select Database:
================
The SELECT DATABASE query is used to select all the fields inside an existing
database. Syntax-
SELECT * FROM database_name;
Create Database:
===============
The CREATE TABLE query is used to create a new table. Following is the syntax for
SQL create table usage-
CREATE TABLE <table_name> (<Field><Datatype><(Width)><constraint>,..);
Drop Table:
===========
The DROP TABLE query is used to drop an existing table. Syntax-
DROP TABLE <table_name>;
Rename Table:
=============
The RENAME query is used to change the name of an existing table. Following is the
syntax-
RENAME old_table_name TO new_table_name;
Truncate Table:
===============
The TRUNCATE TABLE query is used to delete all rows from a table, retaining its
structure. Following is the syntax-
TRUNCATE TABLE <table_name>;
Select * Into
=============
This query is used to copy a table into another table in the same database. Syntax-
SELECT * INTO <required_table> FROM <source_table>;
COMMANDS:
=========
CREATE DATABASE database_name;
DROP DATABASE database_name;
RENAME DATABASE old_database_name TO new_database_name;
SELECT * FROM database_name;
CREATE TABLE <table_name> (<Field><Datatype><(Width)><constraint>,..);
DROP TABLE <table_name>;
RENAME old_table_name TO new_table_name;
TRUNCATE TABLE <table_name>;
SELECT * INTO <required_table> FROM <source_table>;