Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Tuesday, 27 August 2013

A Brief History and Overview of SQL

SQL began life as SEQUEL, the Structured English Query Language, a component of an IBM research project called System/R. System/R was a prototype of the first relational database system; it was created at IBM’s San Jose laboratories in 1974, and SEQUEL was the first query language to support multiple tables and multiple users.
As a language, SQL was designed to be “human-friendly”; most of its commands resemble spoken English, making it easy to read, understand, and learn. Commands are formulated as statements, and every statement begins with an “action word.” The following examples demonstrate this:

CREATE DATABASE toys;
USE toys;
SELECT id FROM toys WHERE targetAge > 3;
DELETE FROM catalog WHERE productionStatus = "Revoked";

As you can see, it’s pretty easy to understand what each statement does. This simplicity is one of the reasons SQL is so popular, and also so easy to learn.

SQL statements can be divided into three broad categories, each concerned with a different aspect of database management:
  • Statements used to define the structure of the Database : These statements define the relationships among different pieces of data, definitions for database, table and column types, and database indices. In the SQL specification, this component is referred to as Data Definition Language (DDL).
  • Statements used to manipulate Data :  These statements control adding and removing records, querying and joining tables, and verifying data integrity. In the SQL specification, this component is referred to as Data Manipulation Language (DML).
  • Statements used to control the permissions and access level to different pieces of Data : These statements define the access levels and security privileges for databases, tables and fields, which may be specified on a per-user and/or per-host basis. In the SQL specification, this component is referred to as Data Control Language (DCL).
Typically, every SQL statement ends in a semicolon, and white space, tabs, and carriage returns are ignored by the SQL processor. The following two statements are equivalent, even though the first is on a single line and the second is split over
multiple lines.

DELETE FROM catalog WHERE production Status = "Revoked";

DELETE FROM
catalog
WHERE productionStatus =
"Revoked";

Tuesday, 12 February 2013

Adding Table and Inserting values


The SQL command used to create a new table in a database typically looks like this:
CREATE TABLE table-name (field-name-1 field-type-1 modifiers,
field-name-2 field-type-2 modifiers, ... , field-name-n
field-type-n modifiers)

The table name cannot contain spaces, slashes, or periods; other than this, any
character is fair game. Each table (and the data it contains) is stored as a set of three
files in your MySQL data directory.

Here’s a sample command to create the members table in the example you saw a
couple sections back:
mysql> CREATE TABLE members (member_id int(11) NOT NULL auto_increment,
fname varchar(50) NOT NULL, lname varchar(50) NOT NULL, tel varchar(15),
email varchar(50) NOT NULL, PRIMARY KEY (member_id));

Thursday, 31 January 2013

Understanding an RDBMS


Every database is composed of one or more tables.
These tables, which structure data into rows and columns, are what lend organization to the data.
Here’s an example of what a typical table looks like:



As you can see, a table divides data into rows, with a new entry (or record) on every row. If you flip back to my original database-as-filing-cabinet analogy, you’ll see that every file in the cabinet corresponds to one row in the table.