Category Archives: Sql
SQL β Select Database
To Select database for work use the following syntax :
Syntax for SQL β Select Database
USE Keyword is used to select the database.
Example
You are now switched to database cusetomersdb.
Now you can perform actions like select , create table etc.
SQL β CREATE Database
SQL β CREATE Database Syntax is used to create a database .
Syntax for SQL β Create Database
The Sytax for CREATE Database is
Example
To See the Databases following command is Used.
SHOW DATABASES;
Which will Show the result as :
SQL β Data Types
Most Common used SQL Data types
char(n) : Fixed n numbers of characters accepted(Memory will be Allocated for n character at the time of creation). Max 8,000 characters allowed.
varchar(n) : Variable n numbers of characters accepted(Memory will be Allocated for the character at run time). Max 8,000 characters allowed.
int : Range β whole numbers from 2,147,483,648 to 2,147,483,647
bigint : Range β whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
smallint : Range β whole numbers from -32,768 32,767
tinyint : Range β whole numbers from 0 to 255
decimal : Range Allows decimal numbers from -10^38 +1 to 10^38 -1
numeric : Allows numbers from -10^38 +1 to 10^38 β1.
text : Variable character string. Maximum 2GB of text data can be accepted.
nchar : Fixed size Unicode string. Maximum 4,000 characters allowed.
nvarchar :Variable size Unicode string. Maximum 4,000 characters allowed.
datetime : Range β From 31 Jan, 1753 to Dec 31, 9999
date : Stores date a date From January 1, 0001 to December 31, 9999
time : Store a time example : 1:00 PM
SQL Syntax
Most Commonly used SQL Keywords are
SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, JOIN, USE, SHOW
Note :
- Sql is case insensitive means you can use both upper case & lower case
- My Sql: If you are using MySql, Table Name are case sensitive means use the table names in MySql as they are
in MySql Database.
Semicolon :
Semicolon after syntax is optional after the each statement but always use semicolon after the statement.
Example
Β
Some Common Sql Commands
1. SELECT
2. INSERT
3. UPDATE
4. JOIN
5. DELETE
6. ALTER
7. DROP
SQL Tutorial
SQL (pronounced βess-que-elβ) stands for Structured Query Language.
SQL is standard language to communicate with a database.
According to ANSI (American National Standards Institute), Sql is the standard language for relational database management systems.
For Selecting all data from Users Table
Following Query is used :