mysql和sqlserver的sql语句区别

1.查询表结构数量等

mysql:
– 查看系统内所有数据库
show databases;
– 查询数据库内所有表
show tables;
– 显示表结构
desc 表名;

sqlserver:
– 查看系统内所有数据库
SELECT name, database_id, create_date FROM sys.databases ;
– 查询数据库内所有表
select * from sysobjects where xtype= ‘U’ ;
– 显示表结构
sp_help/sp_columns 表名;

2.查询前10条数据

mysql:
select * from student limit 10;

sqlserver:
select top 10 * from student ;

3.获取当前时间函数

mysql:
now();

sqlserver:
getdate();

3.从数据库定位到某张表

mysql:
select password from Info.users;

sqlserver:
select password from Info.dbo.users;
或者
select password from Info…users;

3.判断是否为空设置默认值函数

mysql:
isnull(expr1, expr2);

sqlserver:
ifnull(expr1, expr2);

3.分页查询

mysql:

SELECT
     *
FROM
    student
LIMIT (PageNo - 1) * PageSize,PageSize;

sqlserver:

SELECT
    TOP PageSize *
FROM
    (
        SELECT
            ROW_NUMBER () OVER (ORDER BY id ASC) RowNumber ,*
        FROM
            student
    ) A
WHERE
    A.RowNumber > (PageNo - 1) * PageSize;

参考:
https://blog.csdn.net/weixin_37610397/article/details/80273070

你可能感兴趣的:(SQL)