mongodbとmysqlデータ定義とデータ操作

1319 ワード

1.データベースの作成
create database ssm; //mysql
use analysis //mongodb

2.データベースの切り替え
use ssm; //mysql
use analysis //mongodb

3.データベースの削除
drop database ssm; //mysql
db.dropDatabase() //mongodb

4.データ定義とデータ操作
//mysql
create table `teacher`(
   `id` int,
   `name` varchar(20),
   `salary` decimal(7,2),
   `birthday` date,
   `timestamp` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   primary key (`id`)
);
alter table `teacher` drop `birthday`;
alter table `teacher` add  `birthday` date;
drop table `teacher`;
insert into `teacher` ( `id`,`name`,`salary`,`birthday` ) values ( 1,"  ",50000.00,"1997-01-01");
update `teacher` set `salary`=5000 where `name`="  ";                    
delete from `teacher` where `name`="  ";

//mongo
db.createCollection("student")
db.student.drop()
db.student.insert({
    name: '  ', 
    birthday:"2007-01-01",
    scholarship: true,
    success:{"math":80,"data analysis":90},
    tags: [' ', '2016 ', '  '],
    timestamp:parseInt(new Date().getTime()/1000)})
db.student.update({name:'  '},{$set:{name:'  '}})
db.student.remove({name:'  '})