CH 2 Introduction To SQL & SQL Queries
CH 2 Introduction To SQL & SQL Queries
SQL:
TABLES:
A table is a collection of related data entries and it consists of columns and rows.A
table is the most common and simplest form of data storage in a relational
database.
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | Kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
FIELD:
Every table is broken up into smaller entities called fields. A field is a column in a
table that is designed to maintain specific information about every record in the
table.
The fields in the above given Customers table consist of ID, NAME, AGE,
ADDRESS and SALARY.
RECORD/ROW :
A record, also called a row, is each individual entry that exists in a table.A record
is a horizontal entity in a table.
Example,:
There are 7 records in the above Customers table. Following is a single row of data
or record in the Customers table −
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
+----+----------+-----+-----------+----------+
COLUMN:
A column is a vertical entity in a table that contains all information associated with
a specific field in a table.
+-----------+
| ADDRESS |
+-----------+
| Ahmedabad |
| Delhi |
| Kota |
| Mumbai |
| Bhopal |
| MP |
| Indore |
+----+------+
NULL VALUE:
A NULL value is different from a zero value or a field that contains spaces. A field
with a NULL value is one that has been left blank during record creation!
DATA TYPES.
A data type in SQL server is defined as the type of data that any column or
varaiable can store.
1.CHAR (size):
A FIXED length string (can contain letters, numbers, and special characters).
The size parameter specifies the column length in characters - can be from 0 to 255.
Default is 1. Programmers can use this when the length of the characters are known.
2.VARCHAR (size):
A VARIABLE length string (can contain letters, numbers, and special characters).
The size parameter specifies the maximum column length in characters - can be from
0 to 65535. Programmers can use this when the data entries length is varying.
Eg: create table student (name varchar(20),gender char(6),phone number int(10));
3.INT
It is used for storing integer values.
4.DATE
It represents the date including day, month and year.
Format used is YYYY-MM-DD.
SQL COMMANDS:
1.CREATE DATABASE:
This command is used to create your own database.
Syntax:
create database databasename;
Examples:
1: create database asianschool;
2: create database samson10b;
2. SHOW DATABASES :
This command shows all the databases already created in the system
Syntax:
show databases;
Example:
asianschool
samson10b
information_schema
sql_schema
3. USE DATABASES
This command is used to access the specific database.
Syntax:
use databasename;
Example:
use asianschool;
4. DROP DATABASE:
Syntax:
Drop database databasename;
Example:
drop database asianschool;