2

I have the query in postgres sql like below:

-- Table: album
   CREATE TABLE album
   (
    id bigserial NOT NULL,
    artist character varying(255),
    title character varying(255),
    CONSTRAINT pk_album PRIMARY KEY (id )
   )
   WITH (
   OIDS=FALSE
   );
   ALTER TABLE album
   OWNER TO developer;

  -- Table: track
     CREATE TABLE track
     (
     track_id bigserial NOT NULL,
     track_title character varying(255),
     album_id bigint,
     CONSTRAINT track_pkey PRIMARY KEY (track_id ),
    CONSTRAINT fk_track_album FOREIGN KEY (album_id)
     REFERENCES album (id) MATCH SIMPLE
     ON UPDATE CASCADE ON DELETE CASCADE
)
  WITH (
 OIDS=FALSE
   );
     ALTER TABLE track
    OWNER TO developer;

And now I need to convert it to mysql query. But I am confused. How can I do that tutorials? Thanks

1
  • I assume you mean "MySQL" and not "SQL Server" by "mysql server". I've modified the question and title to be unambiguous. Commented Nov 7, 2015 at 17:58

1 Answer 1

1

I'm not quite sure how you want to handle the ownership constructs in MySQL, but the table definitions can be readily converted:

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 is the SQL Fiddle.

The SQL Server version isn't much different:

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
);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank u very much Mr. Gordon. That is what I looking for. :-D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.