Chapter 1: Understanding SQL
1.1 Database Basics
- 1.1.1 What is a Database
For the book’s purposes, a database is a collection of data stored in some organized fashion. Database A container that holds organized data (usually a file or group of data)
- 1.1.2 table
A table is a structured file that can be used to store a particular type of data. Table A structured list of data of a particular type. The data stored in a table is either a type of data or a list, and the list of customers and orders should not be stored in the same database table. Each table in the database has a name that identifies it. This name is unique. However, table names can be the same in different databases.
- 1.1.3 Columns and data
A table consists of columns. Columns store information about a portion of a table. Column A field in a table. All tables are composed of one or more columns. For example, in a customer table, one column stores the customer number and another column stores the customer name. Each column in the database has a corresponding data type. Data types define the types of data that a column can store. Datatype (datatype) the type of data allowed. Each column has a corresponding data type that limits (or allows) the data stored in that column. Data types restrict the kind of data stored in columns. Helps sort data correctly and plays an important role in optimizing disks, so data types should be a special concern when creating tables.
- 1.1.4 line
The data in a table is stored in rows, with each record saved stored in its own row. A record in a row table.
- 1.1.5 the primary key
Each row in a table should have a column (or set of columns) that uniquely identifies itself. Primary key A column (or group of columns) whose value uniquely distinguishes each row in a table. The column (or group of columns) that uniquely identifies each row in the table is called the primary key. A primary key is used to represent a particular row, and it is difficult to update or delete a particular row in a table without a primary key. Any and every column in a table can be used as a primary key if two conditions are met: * No two rows have the same primary key value. * Each row must have a primary key value (the primary key cannot be NULL). A primary key is typically defined on a single column of a table, but it is possible to use multiple columns as primary keys. At this point, the combination of all column values must be unique, but individual column values may not be unique.
1.2 What is SQL
SQL stands for Structured Query Language. SQL is a language specifically designed to communicate with databases.
SQL is made up of very few words, which is intentional.
Advantages of SQL:
- SQL is not a language specific to a particular database vendor. SQL is supported by almost all major DBMSS.
- SQL is simple and easy to learn.
- SQL, while seemingly simple, is actually a powerful language that uses its language elements flexibly to perform very complex and advanced database operations.