SQL Server和MySQL的一些语法区别
< 返回列表时间: 2019-03-26来源:OSCHINA
SQL Server MySQL
查询限制条数 语法:
SELECT TOP number|percent column_name(s) FROM table_name
例子;
SELECT TOP 3 * FROM Customers; 语法:
SELECT * FROM table_name LIMIT number;
例子:
SELECT * FROM ratings ORDER BY category LIMIT 5;
数据类型转换 创建临时表
语法:CONVERT(data_type(length), expression, style)
说明:
data_type:【必要】支持的数据类型
bigint,
int,
smallint,
tinyint,
bit,
decimal,
numeric,
money,
smallmoney,
float,
real,
datetime,
smalldatetime,
char,
varchar,
text,
nchar,
nvarchar,
ntext,
binary,
varbinary,
image

expression:【必要】转换成其他数据类型的值
length:【可选】数据类型的长度
例子:
SELECT CONVERT(varchar, 25.65); 表名必须以“#“开头
CREATE TABLE #MaleStudents
(
name VARCHAR(50),
age int,
gender VARCHAR (50)

)
语法:CONVERT(expr, type) 等价于 CAST(expr AS type)
说明:
expr:转换成其他数据类型的值
type:数据类型
BINARY[(N)]
CHAR[(N)] [charset_info]
DATE
DATETIME
DECIMAL[(M[,D])]
JSON
NCHAR[(N)]
SIGNED [INTEGER]
TIME
UNSIGNED [INTEGER]
例子:
SELECT CONVERT('test', CHAR CHARACTER SET utf8);
SELECT CAST('test' AS CHAR CHARACTER SET utf8); 语法:CREATE TEMPORARY TABLE new_tbl SELECT * FROM orig_tbl LIMIT 0;
热门排行