MySQL基本使用

15263 ワード

          
show databases

現在のデータベースのすべてのテーブルの表示
 show tables
##      
create database demo01 default character set utf8;
##          
use demo01;

##        

create table clazz (
    cid int(10) not null auto_increment primary key,
    cname varchar(100) not null,
    csg varchar(200) unique,    
)

##     
create table student (
    sid int(10) not null auto_increment primary key,      ##    
    sname varchar(100) not null,                          ##    
    ssext char(4) not null,                               ##    
    sbirth date, 
    sfav varchar(200),
    sphone char(11) unique,                               ##  
    cid int(10) references clazz(cid)                     ##    

    ## constraint pk_cid primary key(cid),
    ## constraint un_csg unique key(csg),
    ## constraint fk_cid foreign key(cid) references clazz(cid)
)

##          
## alter table student add constraint pk_cid primary key(cid),
## alter table student add constraint un_csg unique key(csg),
## alter table student modify sphone varchar(100) not null,

     :
                
            alter table student add money float;
                
            alter table student drop sfav;
                  
            alter table student modify sphone int(11)
                
            alter table student rename as stu
               
            drop table student;


    :
            insert into student values(default, '  ', 18, ' ', '2000-01-01');
            insert into student values(default, '  ', 300, ' ', '2000-01-01', 900.00);
            insert into student values(default, '  ', 18, 'a', '2000-01-01');


###############################################################
MySQL auto_increment :
int( ), 10 float/double : varchar( ), char( ), : date, yyyy-mm-dd datetime, yyyy-MM-dd hh:mm:ss 8 timestamp, , 4 time, year, : TEXT, BLOB, ################################################################ : : primary key constraint primary key( ) alter table add constraint primary key( ) : not null alter table modify not null : MySQL : : MySQL , check : ( ) MySQL : unique constraint unique key( ) alter table add constraint unique key( ) : references ( ) constraint foreign key( ) references ( ) alter table add constraint foreign key( ) references ( )
              (on delete set null on update cascase) ############################################################################# : : alter table add , : alter table drop : alter table modify : alter table change : alter table rename as : drop table

#############################################################################

oracle :
     : contact( , )

グループ化:select*from emp order by deptno
ページング:select*fromテーブル名limit n*(m-1)、n(mはページ数、nはページごとの表示数)
外部接続:MySQLでは(+)記号は使用できませんので、外部接続ではSQL 99の構文を使用する必要があります.
delete from:Oracleの構文はdelete[from]です.fromは省略できますが、MySQLではfromは省略できません