MySQL和SQLserver的區(qū)別

1、自增長(zhǎng)列的插入:
SQLServer中可以不為自動(dòng)增長(zhǎng)列插入值,
MySQL中需要為自動(dòng)增長(zhǎng)列插入值。

2、獲取當(dāng)前時(shí)間函數(shù):
SQLServer寫法:getdate()
MySQL寫法:now()

3、從數(shù)據(jù)庫(kù)定位到表。
Sqlserver寫法:庫(kù)名.dbo.表名 ;或者:庫(kù)名..表名
(注:中間使用兩個(gè)點(diǎn))
select password from Info.dbo.users where userName='boss'
或者
select password from Info..users where userName='boss'
mysql寫法:庫(kù)名.表名
select password from Info.users where userName='boss'

4、判斷是否存在某個(gè)數(shù)據(jù)庫(kù),若存在,則刪除
Sqlserver寫法:
IF DB_ID('users') IS NOT NULL
DROP DATABASE users
Mysql寫法:
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寫法:
if exists(select * from sysobjects where name ='Users_test')
drop table Users_test
Mysql寫法:
DROP TABLE IF EXISTS
Users_test

5、主鍵存在,則更新,不存在,則插入
Mysql寫法:
INSERT into users (userID,userName,password) VALUES (1,’jmj’,’123’) ON DUPLICATE KEY UPDATE userName
='jmj', password =123

Sqlserver沒有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寫法:
Select
password from Users where userName='boss' or username=”jmj”
Sqlserver寫法:
Select
password from Users where userName='boss' or username=’jmj’

7、取出查詢結(jié)果中的第一條數(shù)據(jù)或者前幾條記錄(取前幾條記錄只需要修改對(duì)應(yīng)的數(shù)字即可),分頁(yè)也是使用這個(gè)關(guān)鍵字:
SQLServer寫法:
select top 1 password from users where userName='boss'
MySQL寫法:
select password from users where userName='111'limit 0,1
它可以規(guī)定范圍 limit a,b——范圍a-b
8、查詢所有庫(kù)
SQLServer寫法:
select * from [master]..[SysDatabases];
MySQL寫法:
SHOW DATABASES;

9、查詢指定庫(kù)中的所有表
SQLServer寫法:
select *from 庫(kù)名.dbo.[SysObjects]
where[type]='U';
(注:若想知道[type]='U'代表什么意思,請(qǐng)點(diǎn)擊http://www.itdecent.cn/p/a9200a03c338
MySQL寫法:
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ǔ)句一樣。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容