You are on page 1of 8

1

2DBMS

3 DB

4SQL Structured Query Language

DDLCREATEALTERDROP

DMLinsertdeleteupdateselect
DCLgrantrevokedeny

CREATE DATABASE NAME

2DROP DATABASE NAME

4MySQL

1tinyint, smallint, int, bigint(1,2,4,8)

2decimalpsp+2floatps4doublep

s8p s

3date, time, datetime

4char(num), varcharnum, text

5bit

ER

ER ER

QQ

2ER
3

1NF

: 1NF

2NF

2NF

3NF

cmd CREATE TABLE NAME ( col_namecol_type [not

null],)

Use dbname:

2primary key

3references table ( val )

4check

( val>0)

5default

6auto_increment;
7

1describe/desctable_name: filed

2show create tabletable_name \G(format)

1alter table old_namerenametonew_name

2alter tabletable_namechangeold_namenew_namenew_type

3alter tabletable_namemodifyval_namenew_type

4alter tabletable_nameaddnew_val_namenew_type;

alter tabletable_namedropval_name

__

(pk)alter tabletable_nameadd constraintcon_nameprimary key(col_name)

(fk)alter tabletable_nameadd constraintcon_name

foreign key(f_col) references m_table(m_col)

(ck)alter tabletable_nameadd constraintcon_namecheck(exp)

alter table table_namealtercol_nameset default value

alter table table_name modify columncol_nameauto_increment

1drop table [if exists] table_name

alter tablef_table_namedrop forgein keycon_name

1
10

1insert [into] table_namevalues(v1,v2,,vn)

default

2insert[into] table_name(col1,col2,coln) values(v1,v2,vn),

3insert into table_name(col1,col2,,coln) values(v11,v12,,v1n),(v21,)

11

1: updatetable_nameset{col_name = xp}[n]

2updatetable_nameset{col_name = xp}[n]wherecondition_exp

12

1 deletedelete [from] table_name [wherecondition_exp]

2 truncate table truncate tabletable_name where

13

2 select select col1,col2,col3,,coln from table1,table2,,tablen [where

conditions] [group by group_by_list] [Having condintions][order by order_list[asc|desc]]

14

1select all_cols(*) from table

2select cols from table


3select col1 [as] ,coln [as] from table

4distinct

select distinct col from table

5limit

select col from table limit begin_num, all_num

15

1select cols from table where condition_exp

:< >AND OR NOT

2select * from table where col [not] between a and b (

_% n [][^]

select * from table where col [not] like

3select * form table where col is [not] null

16

select col from table order by order_by_list[ASC|DESC]

2,

select col from table order by order_by_list[ASC|DESC] ()

17

18
19

1IN select from table where val in (select val form table)

2EXISTS select from table where exists (select val form table)(

20

select union [all] select union [all]

ALL

Select

21

2 selectcurdate() current_date() curdate()+0

3curtime() current_time() curtime()+0

4current_timestamp(); local_time(); now(); sysdata()

5month(date); monthname(date)

6dayname(date); dayofweek(date) 1 ; weekday(date) 0 ;

week(date) 0 ;

weekofyear(date) ( 1 )
7dayofyear(date); dayofmonth(date); 1

year(date); quarter(date); hour(time) minute(time);second(time)

22

23

24

You might also like