"keywords"
Paimary Key "represents the primary key",
Not NULL "non-null"
Foreign key "represents foreign Key" (Zhu) References "reference" Zhu (code) [Establish foreign key relationship]
Auto_increment "Auto Increment"
Comment Syntax: Use # Annotations,
Create a table
CREATE TABLE Test
(
Create column: Code varchar "string" (write length),
Name varchar (20)
)
Note: 1. Add a semicolon after each statement;
2. The last column does not need to be comma-added;
3. The symbol must be in English;
Garther:
CREATE TABLE Test1
(Code varchar () paimary key "represents the primary key",
Name varchar (20)
);
Set non-null:
CREATE TABLE Test2
(Code varchar () paimary key "represents the primary key",
Name varchar () NOT NULL "non-null"
);
Establish a foreign key relationship: first build the main table goodbye from the table;
Main Table:
Create TABLE Zhu
(
code int parimary Key,
Name varchar (20)
) ;
From the table:
CREATE TABLE Cong
(
Code int PRIMARY KEY,
Name varchar (20),
Zhu Int,
Foreign key "represents foreign Key" (Zhu) References "reference" Zhu (code) [Establish foreign key relationship]
)
Style: Foreign key (column name) references primary table name (column name) foreign key
4. Delete a table
drop table haioyou "table name"
Bad when determining the primary key:
The self-growth column has no meaning but is used for the master key, and the self-growing column can be used as the primary key when the primary key is not found;
Self-growth my user name friend's username
1. Federated PRIMARY Key
2. Add a list of self-growth "auto-increment"
CREATE TABLE Haoyou
(
IDs "Self-growing column name" int "integer" auto_increment "auto increment" primary key,
Me varchar (20),
Friends varchar (20)
)
Job 1. Modifying a statement for a table
2. Add or remove data to the crud operation C:create, r:read query; u:update Modify; D:delete Delete
1.C Adding data
Insert "Insert" into table name values (added value ' n001 ', ' Zhang San ');
INSERT into test3 values (' n002 ', ' Zhang San ');
INSERT into test3 values (' n003 '), make add data
Insert intohaiyou values (' ', ' zs ', ' ls ');
Note: 1. If the added value is a string, you need to add < single quotation marks, if it is another type do not add single quotation marks
2. When adding data, the number of values to match the column even if you do not want to add also write single quotation marks
3. When adding data, you can add to the development column.
4. If the column you want to add is a self-growing column, you can give an empty string.
2. Delete
(1) Delete from table name
Delete from test
(2) Delete from table name where condition
Delete from test where code= ' Noo2 '
3. Modify the data
Update table name set column name = value
Update Test Set name = ' hui '
Update table name set column name = value WHERE condition
Update test set name= ' han ' Where code = ' n2002 '
Creation of database and additions and deletions, creation of foreign keys and primary keys