1别垮、自增長(zhǎng)列的插入:
SQLServer中可以不為自動(dòng)增長(zhǎng)列插入值便监,
MySQL中需要為自動(dòng)增長(zhǎng)列插入值。
2碳想、獲取當(dāng)前時(shí)間函數(shù):
SQLServer寫(xiě)法:getdate()
MySQL寫(xiě)法:now()
3茬贵、從數(shù)據(jù)庫(kù)定位到表。
Sqlserver寫(xiě)法:庫(kù)名.dbo.表名 移袍;或者:庫(kù)名..表名
(注:中間使用兩個(gè)點(diǎn))
select password from Info.dbo.users where userName='boss'
或者
select password from Info..users where userName='boss'
mysql寫(xiě)法:庫(kù)名.表名
select password from Info.users where userName='boss'
4解藻、判斷是否存在某個(gè)數(shù)據(jù)庫(kù),若存在葡盗,則刪除
Sqlserver寫(xiě)法:
IF DB_ID('users') IS NOT NULL
DROP DATABASE users
Mysql寫(xiě)法:
Drop DATABASEif exists
users
拓展:若sqlserver數(shù)據(jù)庫(kù)正在使用中螟左,刪除之前,先要把數(shù)據(jù)庫(kù)變成“單一用戶”觅够,再刪除
ALTER DATABASE users SET SINGLE_USER with ROLLBACK IMMEDIATE IF DB_ID('users') IS NOT NULL DROP DATABASE users
另附:判斷某數(shù)據(jù)庫(kù)中是否存在某張表胶背,若存在,則刪除
Sqlserver寫(xiě)法:
if exists(select * from sysobjects where name ='Users_test')
drop table Users_test
Mysql寫(xiě)法:
DROP TABLE IF EXISTS
Users_test
5喘先、主鍵存在钳吟,則更新,不存在窘拯,則插入
Mysql寫(xiě)法:
INSERT into users (userID,userName,password) VALUES (1,’jmj’,’123’) ON DUPLICATE KEY UPDATE userName
='jmj', password =123
Sqlserver沒(méi)有mysql這樣的關(guān)鍵字红且,只能組合sql語(yǔ)句來(lái)實(shí)現(xiàn)操作:
if not exists (select userID from users where userID= 1)insert into users (userID,userName,password) values(1,’jmj’,’123’) else update users set userName
= ’jmj’, password=’123’ where userID = 1
6坝茎、符號(hào)的使用
mysql對(duì)參數(shù)可以使用單引號(hào),也可以使用雙引號(hào)暇番,對(duì)字段名和表明可以使用反引號(hào)嗤放。
sqlserver只能使用單引號(hào),且不能使用反引號(hào)壁酬。
Mysql寫(xiě)法:
Select
password
from Users where userName='boss' or username=”jmj”
Sqlserver寫(xiě)法:
Select
password from Users where userName='boss' or username=’jmj’
7次酌、取出查詢結(jié)果中的第一條數(shù)據(jù)或者前幾條記錄(取前幾條記錄只需要修改對(duì)應(yīng)的數(shù)字即可),分頁(yè)也是使用這個(gè)關(guān)鍵字:
SQLServer寫(xiě)法:
select top 1 password from users where userName='boss'
MySQL寫(xiě)法:
select password from users where userName='111'limit 0,1
它可以規(guī)定范圍 limit a,b——范圍a-b
8舆乔、查詢所有庫(kù)
SQLServer寫(xiě)法:
select * from [master]..[SysDatabases];
MySQL寫(xiě)法:
SHOW DATABASES;
9岳服、查詢指定庫(kù)中的所有表
SQLServer寫(xiě)法:
select *from 庫(kù)名.dbo.[SysObjects]
where[type]='U';
(注:若想知道[type]='U'代表什么意思,請(qǐng)點(diǎn)擊http://www.reibang.com/p/a9200a03c338)
MySQL寫(xiě)法:
SHOW TABLES
10希俩、某些關(guān)鍵詞的使用
10.1截取字符串
SQLServer只能使用SUBSTRING關(guān)鍵詞來(lái)截取字符串吊宋。
MySQL可以使用SUBSTRING和SUBSTR截取字符串
10.2取得字符串的長(zhǎng)度
SQLServer只能使用Len關(guān)鍵詞取得字符串的長(zhǎng)度。
MySQL可以使用Length取得字符串的長(zhǎng)度斜纪。
11贫母、相同點(diǎn)
delete,select盒刚,insert腺劣,drop(刪除數(shù)據(jù)庫(kù):drop database 庫(kù)名),update因块,create(創(chuàng)建數(shù)據(jù)庫(kù):create
database 庫(kù)名)語(yǔ)句一樣橘原。