• SQLServer和MySql的区别总结


    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());

  • 相关阅读:
    对于Dubbo一些面试题自己的答案
    序列化和反序列化的简单理解
    学习Spring-Session+Redis实现session共享
    Java中的String,StringBuilder,StringBuffer三者的区别
    个人对数据结构的理解和总结
    LeetCode 101. Symmetric Tree
    LeetCode 100. Same Tree
    LeetCode 88. Merge Sorted Array
    LeetCode 83. Remove Duplicates from Sorted List
    LeetCode 70. Climbing Stairs
  • 原文地址:https://www.cnblogs.com/huangzhen22/p/3501732.html
Copyright © 2020-2023  润新知