SQL Server数据库和MySQL数据库有什么区别?(操作角度)

1. 首先说一下sql语句结束标志

mysql以;结束一条SQL语句;SQL server 以;或go或不写结束都可以。不过建议写sql server的时候以go结束,因为sql server很多语句要以等一个语句结束后才能写下一个语句,不然会报批处理错误(深受其害)。


2. 查看表结构数量等

3、查询前几条记录

4、获取当前时间
MySQL写法:now() 
SQLServer写法:getdate()

5、从数据库定位到某张表

1、自增长列的插入:
SQLServer中可以不为自动增长列插入值,

MySQL中需要为自动增长列插入值。

2、获取当前时间函数:
SQLServer写法:getdate()

MySQL写法:now()

3、从数据库定位到表。
Sqlserver写法:库名.dbo.表名 ;或者:库名..表名  (注:中间使用两个点)

select password from Info.dbo.users where userName='boss'

或者

select password from Info..users where userName='boss'

mysql写法:库名.表名

select password from Info.users where userName='boss'

4、判断是否存在某个数据库,若存在,则删除


Sqlserver写法:

IF DB_ID('users') IS NOT NULL

DROP DATABASE users

Mysql写法:

Drop DATABASEif exists users

拓展:若sqlserver数据库正在使用中,删除之前,先要把数据库变成“单一用户”,再删除

ALTER DATABASE users SET SINGLE_USER with ROLLBACK IMMEDIATE IF DB_ID('users') IS NOT NULL DROP DATABASE users

另附:判断某数据库中是否存在某张表,若存在,则删除

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这样的关键字,只能组合sql语句来实现操作:

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、符号的使用
mysql对参数可以使用单引号,也可以使用双引号,对字段名和表明可以使用反引号。

sqlserver只能使用单引号,且不能使用反引号。

Mysql写法:

Select `password` from Users where userName='boss' or username=”jmj”

Sqlserver写法:

Select password from Users where userName='boss' or username=’jmj’

7、取出查询结果中的第一条数据或者前几条记录(取前几条记录只需要修改对应的数字即可),分页也是使用这个关键字:


SQLServer写法:

select top 1 password from users where userName='boss'  

MySQL写法:

select password from users where userName='111'limit 0,1

8、查询所有库


SQLServer写法:

select * from [master]..[SysDatabases];


MySQL写法:

SHOW DATABASES;

9、查询指定库中的所有表
SQLServer写法:

select *from 库名.dbo.[SysObjects] where[type]='U';

(注:若想知道[type]='U'代表什么意思,请点击http://blog.csdn.net/winddai/article/details/5815138)

MySQL写法:

SHOW TABLES

10、某些关键词的使用
10.1截取字符串
SQLServer只能使用SUBSTRING关键词来截取字符串。

MySQL可以使用SUBSTRING和SUBSTR截取字符串

10.2取得字符串的长度

SQLServer只能使用Len关键词取得字符串的长度。

MySQL可以使用Length取得字符串的长度。

11、相同点


delete,select,insert,drop(删除数据库:drop database 库名),

update,create(创建数据库:create database 库名)语句一样。

 
 

猜你喜欢

转载自blog.csdn.net/zam183/article/details/87971098