0

I have created default

CREATE DEFAULT dbo.enviroment AS 'UAT'

I have created user defined type

CREATE TYPE [dbo].[Environment] FROM [varchar](50) NOT NULL

Then I have used it to define user defined type dbo.environment

(using Studio not SP so I see dbo.environment in input "default" but it can be done : sp_bindefault 'dbo.environment','dbo.environment' )

Now I declare variable and select:

declare @env dbo.environment
SELECT @env as env

Result is NULL I would expect 'UAT'

How default should work? Am I doing sth wrong?

Making use of default is possible like in this code:

create table dbo.test (id int, env dbo.environment)
insert into test (id) values(1)
select * from test

but is it possible without a table? (with variable table is not possible as well :( )

I was thinking about providing semi global variable in this way.

SQL SERVER 2008 R2

Luckymag
  • 1
  • 1
  • 1
    Welcome to SO! When you realize you made missteps in your question (e.g. SS2K12 vs. SS2K8R2, "Environment", or "deflaut" instead of "default"), just edit your question to reflect the correct information. – J0e3gan Nov 19 '15 at 17:26
  • @J0e3gan Just curious what is the sense of writing **`2K12`** instead of **`2012`**? When you have the same number of characters – Lukasz Szozda Nov 21 '15 at 14:45

0 Answers0