table of Contents
First, create a database
1. Create a way
In the second chapter we saw how to use PyCharm create SQLite database. For details, see Bowen
use this method to create the database: flask_dev
2. The database naming convention
Uses 26 letters of the alphabet (case-sensitive) and natural numbers (often do not need) 0-9 plus underscore ' ' composed, clear and concise name, multiple words are underlined ' ' separated by a project database, a number of projects carefully use the same database
Second, create a table
Creating tables, comes to naming table, column and data type definitions for each column.
1. Basic Usage
-- 语法
CREATE TABLE database_name.table_name (
column1 datatype PRIMARY KEY,
...
columnN datatype,
);
-- 实例
CREATE TABLE flask_dev.link_men (
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
BIRTHDAY DATETIME NOT NULL,
ADDRESS CHAR(50),
SALARY REAL,
);
Table 2. Data naming
- 26 using letters (case sensitive) and a natural number (often not required), plus 0-9 underscore ' ' composition, clear and simple name, a plurality of words are underlined ' ' separated
- All lowercase names, banned capital
- Prohibit the use of the database keyword, such as: name, time, datetime, password, etc.
- Table name should not be made too long (usually no more than three English words)
- Name of the table is generally a noun or verb-object phrase
- It represents the name of the singular, for example, Employee, instead of employees
- The table must fill out a description (when using SQL statements to build the table)
Name list is as follows: name of the main character table + dtl (detail abbreviation)
such as: name purchase order is: po_order, the purchase order list is: po_orderdtl
Follow the following principles:
Module function points ① + _ Example: alllive_log alllive_category
② Function Point Example: Message Live
③ represents a general embodiment: all_user
3. The field naming convention
- 26 using letters (case sensitive) and a natural number (often not required), plus 0-9 underscore ' ' composition, clear and simple name, a plurality of words are underlined ' ' separated
- All lowercase names, banned capital
- Descriptive information fields must be filled
- Prohibit the use of the database keyword, such as: name, time, datetime password, etc.
- Field name commonly used noun or verb-object phrase
- It takes the name field must be easy to understand, generally no more than three English words
- When naming the list, do not repeat the name of the table
- Do not include data type in the name of the column
- Field is named using the full name, abbreviation ban
For example, avoid using field called employee_lastname in the name of the employe table
follow the following principles:
① noun Example: user_id user_name Sex
② verb-object example phrase: is_friend is_good
Third, delete the table
To remove table definition and all data, indexes, triggers, constraints, and permission specifications of the table.
Once a table is deleted, all the information in the table will be lost forever.
-- 语法
DROP TABLE dababase_name.table_name;
-- 实例
DROP TABLE flask_dev.link_men;