How to set a default value created by the user in the creation of a table (SQL Server)?

Asked

Viewed 526 times

0

I created a default value for my database:

CREATE DEFAULT [dbo].[zero] as 0

But I cannot create a table using this default value created. How do I set this value when creating a table? For example:

CREATE TABLE TESTE ( num int DEFAULT zero)

1 answer

1

You can set the value default field "num" when creating the TEST table like this:

CREATE TABLE TESTE
(
    num int DEFAULT (0)
)

This "CREATE DEFAULT" feature will be removed in a future version of Microsoft SQL Server in accordance with msdn, then it’s good to avoid it.

  • So, but the idea would be to take advantage of the default zero for other tables as well, then if I ever wanted to change the value I would change the default and this would replicate for all tables. The zero in this case was more of an example, but it was worth.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.