Home Ask Login Register

Developers Planet

Your answer is one click away!

Jojo February 2016

Generic auto-increment foreign key

I'm writing sql scripts which I would like to run across platforms (mostly mysql and postgres). The problem I see is I cannot arrive at a common one for auto-increment primary keys which are used as foreign keys. Is there a way to do this ?

table t1 ( column c1 )
table t2 ( column c2 )

c1 is auto increment and c2 is a foreign key referenced on c1.

I tried keeping c1 as SERIAL and c2 as bigint/bigint unsigned/numeric , but no luck.


Gordon Linoff February 2016

Really, it is futile to try to get SQL code to work across multiple database platforms. There are just too many variations on the language.

In fact, the syntax for a stored procedure differs significantly between the two. So, you are going to have to write separate scripts for each database you want to support.

Post Status

Asked in February 2016
Viewed 3,145 times
Voted 10
Answered 1 times


Leave an answer

Quote of the day: live life