Introduction to SQL: 1.Understanding SQL

This post is heavily based on Sams Teach Yourself SQL in 10 Minutes (Fourth Edition). Please consider to buy the book if you find this post useful.

Database Basics

Databases

Let’s define database as a collection of data stored in some organized fashion. You can think of it as a filing cabinet.

Tables

A table is a structured list of data of a specific type. It might contain a list of customers, a product catalog, or any other list of information. Files within the filing cabinet can be thought as tables.

Each table stores unique data type or list to ease data retrieval and access. While you cannot use the same table name twice in the same database, you definitely can reuse table names in different databases.

Schema

Schema is information about database and table layout and properties. These include information about what data may be stored, how it is broken up, how individual pieces of information are named.

Columns and Datatypes

Tables are made up of columns. A column contains a particular piece of information within a table. You can imagine tables as grids, somewhat like spreadsheets. Each column in the grid contains a particular piece of information. Each column in a database has an associated datatype.

Datatype

A type of allowed data. Every table column has an associated datatype that restricts (or allows) specific data in that column.

Rows

Data in a table is stored in rows; each record saved is stored in its own row. Envisioning a table as a spreadsheet style grid, the vertical columns in the grid are the table columns, and the horizontal rows are the table rows.

Primary Keys

Primary keys are a column (or set of columns) whose values uniquely identify every row in a table. These keys are the IDS for each rows. For example, it could be employees SSN Numbers. The primary key is used to refer to a specific row.

The folowing rules apply to Primary Keys:

  • Primary key value has to ne unique.
  • Every row MUST have a primary key value. No NULL values are allowed.
  • Values in primary key columns should never be modified or updated.
  • Primary key values should NEVER be reused in the future.

What Is SQL?

It stands for Structured Query Language and is promounces as sequel. It is a language to communicate with databases. The biggest advantage of SQL is that SQL is not a proprietary language used by specific database vendors. Almost every major DBMS (Database Management Systems) supports SQL.

Related

Next
Previous