MySQL Data Sheet
- C (Create): Creating
1. Syntax:
Create table Table (
Column name Data type 1,
column name datatype 2 2,
....
Column Name Data Type n n
);
Note: The last column, no comma (,)
database type:
1. int: integer type
Age int,
2. Double: decimal type
Score Double (5,2)
3. dATE: date, contains only the date, the MM-dd-YYYY
4. datetime: date, time division comprising date sec yyyy-mM-dd HH: mm: ss
5. The timestamp: time Minutes wrong type comprising yyyy-mM-dd HH when date: mm: ss
If you do not assign to this field in the future, or assignment is null, the system defaults to the current time, to automatically assign
6. varchar: String
name varchar (20): name up to 20 characters
zhangsan 8 characters seating two characters
Create a table example:
Create table Student (
ID int,
name VARCHAR (32),
Age int,
Score Double (4,1),
Birthday DATE,
the insert_time timestamp
);
replicate table:
Create table like table table being copied;
- R (Retrieve): inquiry
Query a database of all the table names
show tables;
lookup table structure
desc table name;
- U (Update): Modify
1. Modify the table name
alter table table name rename to the new name;
2. modify character set table
alter table table name character set character set name;
3. Add an
alter table table add Column Name Data Type;
4. Modification column name type
alter table change table column names new column not new data types;
alter table column name table modify the new data type;
5. remove column
alter table drop table column name;
- D (Delete): Delete
drop table 表名;
drop table if exists 表名 ;
Detailed description:
A, MySQL create a data table
Create a MySQL data tables need the following information:
- Table Name
- Table Field Name
- The definition of each table field
grammar
The following is a table of data to create MySQL SQL general syntax: here (CREATE TABLE can be lowercase)
CREATE TABLE table_name (column_name column_type);
Create a table from the command prompt
By mysql> command window can be very simple to create MySQL data tables. You can use the SQL statement CREATE TABLE to create a data table.
Examples
The following is an example to create a student data sheet:
create table student(
id int,
name varchar(32),
age int ,
score double(4,1),
birthday date,
insert_time timestamp
);
Copy the table:
the table name create table table name like to be copied;
2, MySQL delete data table
Be very careful when deleting data in MySQL tables are very easy to operate, but you then delete the operating table, because the delete command all data will be lost.
grammar
The following is the Delete MySQL data tables can also be universal grammar :( lowercase)
DROP TABLE table_name ;
Delete data table in the command prompt window
Delete data table SQL statement mysql> command prompt window for DROP TABLE :
Examples
The following example deletes the data table wen1:
3, MySQL modify data table
1. Modify the table name
alter table table name rename to the new name;
2. modify character set table
alter table table name character set character set name;
3. Add an
alter table table add Column Name Data Type;
4. Modification column name type
alter table change table column names new column not new data types;
alter table column name table modify the new data type;
5. remove column
alter table drop table column name;