如何将postgres sql转换为mysql查询

时间:2015-11-07 17:50:23

标签: mysql sql database postgresql

我在postgres sql中有如下查询:

std

现在我需要将其转换为mysql查询。但我很困惑。我该怎么做那个教程?谢谢

1 个答案:

答案 0 :(得分:1)

我不太确定你想如何处理MySQL中的所有权结构,但表定义可以很容易地转换:

CREATE TABLE album (
    id bigint NOT NULL auto_increment,
    artist varchar(255),
    title varchar(255),
    CONSTRAINT pk_album PRIMARY KEY (id)
);

CREATE TABLE track (
    track_id bigint NOT NULL auto_increment,
    track_title varchar(255),
    album_id bigint,
    CONSTRAINT track_pkey PRIMARY KEY (track_id ),
    CONSTRAINT fk_track_album FOREIGN KEY (album_id)
    REFERENCES album (id) ON UPDATE CASCADE ON DELETE CASCADE
);

Here是SQL小提琴。

SQL Server版本并没有太大差异:

CREATE TABLE album (
    id bigint NOT NULL identity,
    artist varchar(255),
    title varchar(255),
    CONSTRAINT pk_album PRIMARY KEY (id)
);

CREATE TABLE track (
    track_id bigint NOT NULL identity,
    track_title varchar(255),
    album_id bigint,
    CONSTRAINT track_pkey PRIMARY KEY (track_id ),
    CONSTRAINT fk_track_album FOREIGN KEY (album_id)
    REFERENCES album (id) ON UPDATE CASCADE ON DELETE CASCADE
);