SQL与NoSQL的CRUD对照
flyfish 2015-7-21
Create, Read, Update and Delete (CRUD)
SQL方式
查
增
删
改
NoSQL方式(MongoDB)
查
增
删
改
对照
flyfish 2015-7-21
Create, Read, Update and Delete (CRUD)
SQL方式
查
SELECT 列名称 FROM 表名称 SELECT * FROM 表名称 SELECT 列名称 FROM 表名称 WHERE 列 运算符 值
增
INSERT INTO 表名称 VALUES (值1, 值2,....) INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
删
DELETE FROM 表名称 WHERE 列名称 = 值
改
UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值
NoSQL方式(MongoDB)
查
db.collection.find(query, projection) db.products.find( { qty: { $gt: 25 } } )
增
db.collection.insert() db.products.insert( { item: "card", qty: 15 } )
删
db.collection.remove() db.products.remove( { qty: { $gt: 20 } } )
改
db.collection.update(query, update, options) db.people.update( { name: "Andy" }, { name: "Andy", rating: 1, score: 1 }, { upsert: true } )
对照
SELECT * FROM users WHERE age=18 db.users.find({age:18}) INSERT INTO USERS VALUES('sss',18) db.users.insert({name:'sss',age:18}) UPDATE users SET age=18 WHERE name='sss' db.users.update({name:'sss'}, {$set:{age:18}}, false, true) DELETE FROM users WHERE age=18 db.users.remove({age:18});