-sql -DDL

Column operations

1
2
3
4
5
6
7
8
9
10
11
12
desc table; ...................................... # View table structure 
alter table table name add column name attribute; # add columns ..............
alter table add column name of the attribute table after column name; ... # specify added behind a column
alter table drop column table name; .............. # delete the column name
alter table table name change old column names new column name for the new property ..... # modify the column name
alter table a modify change_username varchar (20 ); # modify column properties

alter table a add new_username char (10 ); # add column
alter table a add new_username2 char (10 ) after id; # add columns, designated added after a column
alter table a drop new_username2; # delete column name
alter table a change new_username change_username char (5); # modify the column name
alter table a modify change_username varchar (20 ); # modify column properties

Operating Table

1
2
3
4
5
6
7
8
9
10
11
12
13
14
show tables; # View all the tables 
desc table name; # View table structure
show create table table name; # Create a table view SQL
show tables; # Display information
show table status where name = 'table name'; # to view a table in a information
rename table the old table to the new table name table name # modify
delete from user_t; # Clear the table of contents
truncate user_t; # id table of contents emptied from the beginning

# View
show create view view name # View Jian view the process of
drop view view name # delete the view
create view v1 as select * from student2 # create the view behind as with ordinary SQL
the Create View v2 as the SELECT the above mentioned id, name, Score from STUDENT2 # Create a view behind as with ordinary sql

index

. 1 
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
13 is
14
15
16
. 17
large column   -sql -DDL LASS = "Line"> 18 is
. 19
20 is
21 is
22 is
23 is
24
25
26 is
27
28
29
# Ordinary index (index another name Normal), 
# unique index (UNIQUE),
# full-text indexing (FULLTEXT),
# space index (SPATIAL)

unique key email (email (10) ) # length using an index
alter table table add index index name (field name) # add a normal index
alter table table name drop index index name # delete index
show index from the index table # View

create table a1(
name char(5),
email char(15),
key name(name),
unique key email(email)
);

# Multicolumn index
Create Table A3 (
name char (. 5),
In Email char (15),
Key name (name),
UNIQUE Key name_email (name, In Email)
);
EXPLAIN SELECT * from A3 the WHERE name = "Zhang"; # Analysis SQL
the ALTER the Table a1 the Add uNIQUE (name); # add a unique index
alter table a1 add index index_name (email ) # add a normal index
alter table a1 drop index index_name # delete indexes
show index from a1 G # View index

!!! library operations [This operation is more dangerous, please exercise caution]

1
2
3
4
5
6
7
create database database; # create database 
create database database default character set the character set collate collation; # specify the character set to create a library

create database yourdb; # create database
create database yourdb3 default character set utf8mb4 collate utf8mb4_unicode_ci; # specify the character set to create a library

Name !!! databases do not directly modify, easy to lose data !!!

Not commonly used, have practical use sql

1
2
3
4
5
The SELECT 
name,
NULL Hello the AS, --- NULL as a
"foo" AS bar --- string as a
FROM student2

Add Column

Guess you like

Origin www.cnblogs.com/lijianming180/p/12099731.html
DDL