Introduction To SQL
Introduction To SQL
In the mid-1970’s, SQL that the MYSQL was developed as the data
manipulation language for IBM’S prototype relational model DBMS,
System R. under the name SEQUEL, at IBM’s San Jose research facilities.
In 1980. the language was renamed SQL (but still pronounced ‘sequel’
although the equally popular pronunciation of S-Q-L is used in this text,
to avoid confusion with an unrelated hardware product name SEQUEL.
Most DBMS use a version of SQL as their data manipulation language.
In this lesson, you will learn the basics of working in MySQL. You
will learn how to assign data types to columns in a database. You also
will learn about a special type of value, called a null value. And learn
how to handle these values and adding data to them. Finally, you will
learn how to describe a table’s layout using MySQL.
What is Database
It is a structured set of data held in computer / server,which can
be accessed programs / software for use in their system.
DATA STRUCTURE
(FULL SCHEMA)
Table DATA
tbl_users
INSERT INTO
Database
db_ecommerce
Table
DATA
tbl_shops
INSERT INTO
CREATING A DATABASE
CREATE DATABASE database_ecommerce;
CREATING A TABLE
CREATE A TABLE table_name (variable datatype);
Or
CREATE A TABLE table_name (variable datatype constraint);
DATA STRUCTURE
(FULL SCHEMA)
tbl_users
UID userName emailAddress ownedShop
1 MBCSchool [email protected] MBCshop
2 John Doe [email protected] none
3 Alan Blake [email protected] shop
4 Ray Hogan [email protected] none
DATABASE STRUCTURE
(Primary Key)
UID
1
2
3
4
CONSTRAINTS
1. NOT NULL - will not accept empty values. Occasionally, when you enter a
new row into a table or modify an existing row, the values for one or more
columns are unknown or unavailable. For example, you can add a customer’s
name and address to a table even though the customer does not have an
assigned sales rep or established credit limit. In other cases, some values
might never be known-- perhaps there is a customer that does not have a
sales rep. In SQL, you handle this situation by using a special value to
represent cases in which an actual value is unknown, unavailable , or not
applicable. This special value is called a null data value, or simply a null.
When creating a table, you can specify whether to allow nulls in the individual
columns.
Question: Should a user be allowed to enter null values for the primary key?
Implementation of Nulls
In SQL, you use the NOT NULL clause in a CREATE TABLE command
to indicate that cannot contain null values. The default is to allow nulls,
column for which you do not specify NOT NULL, can accept null values.
3. Primary Key - will not accept empty and duplicate values. Another
important concept of database design is that of the primary key. In the
simplest terms, the primary key is the unique identifier for a table.
AUTO_ INCREMENT
NUMERIC DATA
TEXT DATA
TIME DATA
MISCELLANEOUS DATA
BLOB - Stores large binary data.
CREATING A DATABASE
The INSERT command adds rows to a table. You type INSERT INTO
followed by the name of the table into which you are adding data. They you
type of the VALUES command followed by the specific values to be inserted
in parentheses. When adding rows to character columns, make sure you
enclose the values in single quotation marks. (for example , ‘kaiser’). you also
must enter the value in the appropriate case, because character data is stored
exactly as you enter it.