SQLServer和MySql的区别总结

时间:2021-06-09 03:58:03

SqlServer支持like '%'+'87'+'%' 拼接字符串  但MySql里不支持,只能用CONCAT('%','87','%')拼接,否则异常

1.递归函数的区别
类别表
CREATE TABLE [dbo].[stock_category](
[ID] [varchar](50) NOT NULL,
[ParentID] [varchar](50) NULL,
[CategoryName] [nvarchar](128) NOT NULL,
[Depth] [int] NULL,
[SortIndex] [int] NULL,
[UselessYear] [int] NULL,
[CreateDate] [datetime] NULL,
[Remarks] [nvarchar](512) NULL,
CONSTRAINT [PK_stock_category] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SQLServer中:表值递归函数
CREATE function [dbo].[GetCategoryIDList] (@id varchar(50))
returns @t table(id varchar(50))
as
begin
insert @t select ID from dbo.stock_category where ParentID = @id
while @@rowcount > 0
insert @t select a.ID from stock_category as a inner join @t as b
on a.ParentID = b.id and a.ID not in(select id from @t)
return
end
运行:select id from [dbo].GetCategoryIDList('......');
MySQL中:
create funtion 'GetCategoryIDList'(rootId varchar(50))
return varchar(1000)
BEGIN
DECLARE sTemp VARCHAR(1000);
DECLARE sTempChd VARCHAR(1000);

SET sTemp = '$';
SET sTempChd =cast(rootId as CHAR);

WHILE sTempChd is not null DO
SET sTemp = concat(sTemp,',',sTempChd);
SELECT group_concat(ID) INTO sTempChd FROM stock_category where FIND_IN_SET(ParentID,sTempChd)>0;
END WHILE;
RETURN sTemp;
END
运行:select ID from stock_category where find_in_set(ID,GetCategoryIDList('......'));
2.生成GUID
SQLServer:NEWID(); MySQL:UUID();
3.日期函数:
MySQL:Date_Add(now(),interval 1 year);
SQLServer:AddDate(year,1,getdate());