Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a scalar database variable in SQL Server?

We are creating a schema version for our database. Right now we have a database table with a column version and a single row with the version.

Is it possible to make a scalar variable on the database, rather than a table?

Something like:

SET DBNAME.dbo.DBVersion = 1;

like image 718
Spence Avatar asked Sep 19 '26 04:09

Spence


1 Answers

You may consider to store a scalar value in an Extended Property attached to your database.

To add an extended property use sp_addextendedproperty

EXEC sp_addextendedproperty @name = N'DBVersion', @value = '1';

To get a value of your property fn_listextendedproperty

SELECT value FROM fn_listextendedproperty(N'DBVersion', default, default, default, default, default, default);

Output:

Value
-----
    1

Further reading:

  • Using Extended Properties on Database Objects
like image 168
peterm Avatar answered Sep 21 '26 19:09

peterm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!