CygnusX1
CygnusX1

Reputation: 21808

Persistent variable in an SQL database?

Is there a way to declare a simple (persistent) variable as a part of an SQL database?

I am trying to implement by hand a mechanism similar to auto_increment, but not associated with any particular field or table. Each time one of a set of my procedures is called, I would like that variable to be incremented.


I have found that you can create local, session and global variables. However:


A possible walkaround that I can think of would involve creating a table with just a single row in it. I am looking for a cleaner approach though - if that exists...

Upvotes: 3

Views: 1166

Answers (1)

Patrick Hofman
Patrick Hofman

Reputation: 157038

Creating a table is probably your best option, since after all, that is the database server's place where it stores its (persistent) data.

You can also take advantage of all the nice things a database does for you, like locking, auditing, etc.

Upvotes: 4

Related Questions