mysql basic syntax (section)

##### database operations
- 0. Display Database
Show Databases;
- 1. Create a database
create database if not exists database name = utf8 charset;
the Create Database `create`; # add back quotes you can use the keyword

- 2. Delete database
drop database database name;
drop database IF EXISTS database name;

- 3. The Create database sql statements
show create database database name;

- 4. Modify the database, note that you can only modify the coding
alter database database name of the charset = character encoding;
Show the Create Database database name; # View modified data

- 5. Select Database
use database name;


Operating table structure #####
- 1. Display table
show tables;

- 2. Create a header
# int, varchar data type
# null null
# default defaults
# auto_increment automatic growth
# primary key primary key is generally used as the primary key ID
# commnet Note
# engine engines innodb (now with more, do not write ) myisam memory of these three
the create the table IF EXISTS not STU (
the above mentioned id int,
name VARCHAR (30),
);
# create a table view

- to create complex tables
create table if not exists table name (
the above mentioned id int not null Primary Key AUTO_INCREMENT,
name VARCHAR (20) not null the CommNet 'name',
Phone VARCHAR (20) the CommNet "phone number",
addr VARCHAR (100) default "address unknown" commnet "address",
) = InnoDB Engine;

set name gbk; # as long as is necessary to write this sentence with the Chinese

- created in the current database to another database table
create table name of the database table names (.
The above mentioned id int not null Primary Key AUTO_INCREMENT,
name VARCHAR (20) not null the CommNet 'name',
Phone VARCHAR (20) the CommNet "phone number"
addr varchar (100) default "address unknown" commnet "address",
) = InnoDB Engine;

- 3. The statement creates a table display

show create table table;
show create table table \ G; # arranged vertically

- See Table 4. Structure (DESCRIBE)
desc table;

- Table 5. Remove
drop table table name;
drop table IF EXISTS table;
drop table table 1, table 2;

- Modify Table 6.
# Add fields
alter table table add [Column Name] Field Name Data Type [position]
# for example: the only two
alter table jing_dong the Add int Age;
alter table jing_dong the Add e main VARCHAR (30) First; # Add a position on the first field
alter table jing_dong add sex varchar (2 ) after name; # add sex field name field in this latter

# Delete field
aler table jing_dong drop emain; # delete this bullet emain

Modify the fields #
# renamed
alter table Change table name [Column Name] original field | new field data type;
# examples
alter table teahcer Change Sex xingbie int;
# not renamed
# gender data type to VARCHAR
alter table Teacher Modify xingbie VARCHAR (2);

Engine # engine is determined to modify the way data is stored
alter table table name engine = myisam;

# Modify the table name
alter table table name rename to new table name;

- 7. Operation Data
# insert data
insert table table (field 1, field 2, field 3, field 4) values (value 1, value 2 and value 3, value 4);

# Query
select * from table name;

Guess you like

Origin www.cnblogs.com/YLlang/p/11005774.html