1. Create a database
Create Datebase table name
2. Deleting a database
Drop Datebase Table Name
3. Create a table
-CREATE TABLE Test (table name)
(
Code(column name) varchar(column type, string type)(string length),
Name varchar (20)
);
-CREATE TABLE Test1
(
Code varchar ( primary key),
Name varchar (20)
);
Primary KEY Primary Key
CREATE TABLE Test2
(
Code varchar (primary key),
Name varchar (not null )
); NOT NULL non-null
-CREATE table Zhu
(
Code int PRIMARY KEY,
Name varchar (20)
);
CREATE TABLE Cong
(
Code int PRIMARY KEY,
Name varchar (20),
Zhu Int,
Foreign key (Zhu) references Zhu (code)
);
Foreign key (column name) references primary table name (column name) foreign key
CREATE TABLE Haoyou
(
IDS int Auto_increment primary KEY,
Me varchar (20),
Friends varchar (20)
);
Auto_increment Self-growing column
Note: 1. Add a semicolon after each statement
2. The last column is followed by a comma
3. The symbol must be in English
To change the data and to search and delete
CRUD Operations
C:create add
R:read Query
U:update modification
D:delete Delete
1.C: Add Data
Insert into table name values (' n001 ', ' Zhang San ');
INSERT into test2 values (' n001 ', ');
INSERT into Test2 (code) VALUES (' n001 '); Specify columns to add
INSERT into haoyou values (' Zs ', ' ls ');
Attention:
1. If the added data 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 matches the column
3. When adding data, you can specify a column to add
4. If the column you want to add is a self-growing column, you can give an empty string
5. Comment Syntax: #
CRUD Operations
1. Increase
Insert into table name values (column values, column values)
Insert into table name (column name, column name) values (value, value)
2. Delete
Delete from table name
Delete from test
Delete from table name where condition
Delete from test where code= ' n002 '
3. Modifications
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= ' n002 '
1201 New Course TSQL Statement