Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

CH 2 Introduction To SQL & SQL Queries

Uploaded by

9574
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

CH 2 Introduction To SQL & SQL Queries

Uploaded by

9574
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

UNIT 2

INTRODUCTION TO SQL AND SQL QUERIES

SQL:

SQL stands for Structured Query Language.


SQL is a standard database language for storing, manipulating and retrieving data
stored in a relational database. All the Relational Database Management Systems
(RDMS) like MySQL, MS Access, Oracle, Sybase, Postgres and SQL Server use
SQL as their standard database language. SQL is a standard language for accessing
and manipulating databases.
RDBMS

RDBMS stands for Relational Database Management System.

TABLES:

The data in RDBMS is stored in database objects called 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.

Example: customers table

+----+----------+-----+-----------+----------+
| 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.

Example: The ADDRESS column in the Customers table, which represents


location description is shown as below.

+-----------+
| ADDRESS |
+-----------+
| Ahmedabad |
| Delhi |
| Kota |
| Mumbai |
| Bhopal |
| MP |
| Indore |
+----+------+
NULL VALUE:

A NULL value in a table is a value in a field that appears to be blank, which


means a field with a NULL value is a field with no value.

If a column in a row has no value , then column is said to be null.

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!

What Can SQL do?

 SQL can execute queries against a database


 SQL can retrieve data from a database
 SQL can insert records in a database
 SQL can update records in a database
 SQL can delete records from a database
 SQL can create new databases
 SQL can create new tables in a database

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:

This command is used to is used to drop an existing SQL database.

Syntax:
Drop database databasename;
Example:
drop database asianschool;

You might also like