1. Database Login operation:
Database Login
- - - -P
Local login:
Mysql-u root-p
2. Database Management operations:
View all databases:
show databases;
Create a new database and set the database encoding to UTF8:
Create database db character set UTF8;
Modify the database encoding to UTF8:
Alter database db charset=UTF8;
To display the CREATE database information:
Create database db;
To delete a database:
Drop database db;
Drop Database if exists db;
3. Data Sheet Management operations
View Data Sheet:
Show tables;
To create a table:
Create Table int Char (int);
To display the CREATE table information:
Create table name;
Add Field:
Alter Table Add Char (4);
To delete a field:
Alter Table drop field name;
To modify the data type of a field:
Alter Table varchar (a);
Modify the data type of the field and change the field name:
Alter Table Number smallint;
To delete a data table:
Drop Table if exists Stu;
4. Data management operations:
Data query:
Select * from Stu;
Insert data:
A. Inserting all fields
Insert into Stu value (1'Tom');
B. Inserting a specified field
Insert into Stu (ID, name) value (2'jack');
C. Inserting more than one piece of data
Insert into Stu value (3'rose'), (4'John ');
To modify the data:
A. All modifications
Update Set Age=;
B. Selective modification
Update Set name='Alice'where name='Jack ';
Delete data:
A. Delete all data and cannot be recovered
truncate Stu;
B. Delete all data to restore
Delete from Stu;
C. Deleting data that satisfies a condition
Delete from where id=1;
5. Database constraints
PRIMARY KEY constraint
Create Table int Primary Key Char (ten));
Automatic growth
Create Table int Primary Key varchar (ten))
Uniqueness constraints:
Create Table int Unique Char (ten));
Non-null constraint:
Create Table int Char (notnull);
Default constraints:
Create Table int Char (default'NoName');
FOREIGN KEY constraints:
Create Table int Primary Key Char (ten)); Create Table int Primary Key Char (intforeignkeyreferences fclass (ID));
Delete the Foreign Key association table (first delete the table associated with the foreign key)
Drop Table fstudent; Drop table Fclass;
CHECK constraints:
create table tchk (id int , age int check ( Age > 0 and age < 150 ), gender char ( Span style= "color: #800000; Font-weight:bold ">10 ) check (Gender= " boy '
To increase the PRIMARY KEY constraint:
Alter Table Add constraint Primary Key (ID);
To delete a PRIMARY KEY constraint:
Alter Table Drop Primary key;
To add a FOREIGN KEY constraint:
Alter Table Add constraint Foreign Key references TPK (ID);
To delete a foreign KEY constraint:
Alter Table Drop Foreign Key fk_id
MySQL Command Collation 1