zoukankan      html  css  js  c++  java
  • 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());

  • 相关阅读:
    个人工作总结6
    使用java对文件批量重命名
    导入csv文件到数据库
    关于微信小程序的Request请求错误处理
    基于jPlayer的三分屏制作
    条件查询时,如果有的输入框不输入,后台应该怎么处理?
    mysql 1449 : The user specified as a definer ('root'@'%') does not exist 解决方法
    C++&&Objective-c
    加载ttf字体
    ios6去除高光效果,和判断iphone或ipad设备
  • 原文地址:https://www.cnblogs.com/huangzhen22/p/3501732.html
Copyright © 2011-2022 走看看