0

我正在尝试将以下 SQL Server 代码转换为 MySql ...

  SELECT 
        columns  = COALESCE(columns + ',', '') + Cast(sc.name AS char(64))
  FROM 
        sysColumns sc 
  INNER JOIN 
        sysObjects so ON sc.ID = so.ID
  WHERE 
        so.type = 'u'; AND 
        so.name = tableName;

此转换是否有任何工具或参考链接?

我发现我可以使用all_sourceforsysObjects但不确定用于sysColumnstableName.

请问有什么建议吗?

4

1 回答 1

0

SQL小提琴

MySQL 5.5.30 架构设置

CREATE TABLE IF NOT EXISTS `category` (
  `id` int(11) NOT NULL,
  `parent_id` int(11) NOT NULL,
  `label` varchar(20) NOT NULL,
  `level` int(11) NOT NULL,
  `path` varchar(100) NOT NULL,
  `sortorder` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

查询 1

SELECT t.table_name,
  group_concat( c.column_name ORDER BY c.ordinal_position ) AS columns
FROM information_schema.tables t
  JOIN  information_schema.columns c ON t.table_name = c.table_name
WHERE t.table_name = 'category'
GROUP BY t.table_name

结果

| TABLE_NAME |                                 COLUMNS |
--------------------------------------------------------
|   category | id,parent_id,label,level,path,sortorder |
于 2013-02-26T23:17:17.397 回答