databases
which store and organize data electronically
let's imagine that
Let's imagine that we are in charge of storing and organizing data for a
... [Show More] library. 用于举例
set up a database
建立数据库
house
This information is housed in objects called tables, with data organized into rows and columns.
This database contains
This database contains a patrons table, a books table, and a checkouts table.
a closer look at ... shows that
A closer look at the patrons table shows that it stores various data about our library's patrons, like...
the total overdue fines the patron owes our library
顾客欠图书馆的罚款总额
A relational database
defines relationships between tables of data inside the database.
database advantages
1. Databases can store much more data, 2. and storage is more secure due to encryption. 3. Possibly the biggest advantage of a database is that many users can write queries to gather insights from the data at the same time.
SQL
SQL is short for Structured Query Language. It is the most widely used programming language for creating, querying, and updating relational databases.
Now that
Now that we know the basic organization of a database, let's take a closer look at the main building block of databases: tables! 前面已经讲完了概况后可以用now that 承上启下
tables
databases are organized into tables, which hold related data about a particular subject.
table names
Table names should be
1. lowercase and
2. should not include spaces - we use underscores in place of spaces.
3. And ideally, a table name would refer to a collective group (like "inventory") but it's also okay for the table to have a plural name (such as "products").
records
A record is a row in a table. It holds data on an individual observation.
如何描述table中records的情况
Taking a look at the patrons table, we see that the table has four records: one for each of the patrons.
feilds
A field is a column in a table. It holds one piece of information about all observations in the table.
如何描述table中field的情况
The "name" field in the patrons table lists all of the names of our library patrons.
field naming
1. Generally, field names should be lowercase and should not involve spaces.
2. A field name should be singular rather than plural because it refers to the information contained in that field for a single record.
3. Similarly, two fields in a table cannot have the same name.
4. Finally, field names should never share a name with the table they are housed in..
a unique identifier (key)
A unique identifier, sometimes called a "key," is just what it sounds like: a unique value which identifies a record so that it can be distinguished from other records in the same table.
it make sense to
In the patrons table, it makes sense to use the card_num field as the unique identifier for each patron
why chose data type for each feild
1. First, different types of data are stored differently and take up different amounts of storage space.
2.Second, some operations only apply to certain data types.
string
a "string" refers to a sequence of characters such as letters or punctuation.
VARCHAR
SQL's VARCHAR data type is more flexible and can store small or large strings - up to tens of thousands of characters!
INT
Integer data types store whole numbers, INT, a common SQL integer data type, can store numbers from less than negative two billion to more than positive two billion!
Numeric
Float data types store numbers that include a fractional part, The NUMERIC data type can store floats which have up to 38 digits total - including those before and after the decimal point.
Schema
Schemas are often referred to as "blueprints" of databases.
1. A schema shows a database's design, such as what tables are inclu [Show Less]