Question

When I looked at the tables in Adventure works, the design of each columns seems a bit strange. Since AdventureWorks shows industrial standards I want to follow it.

In Phone number columns they have given type for the column as Phone:nvarchar(25)

  1. Why they've add type as Phone:nvarchar(25) ?
  2. What's the difference bewteen Phone:nvarchar(25) and nvarchar(25) ?
  3. I've tried to manualy type the type of phone column as Phone:nvarchar(25) but it gave me an error. why it gives me an error?

How do I make the phone column of type Phone:nvarchar(25)?

Was it helpful?

Solution

There's a user defined type in the Adventure Works database called Phone. If you want to create it yourself, you can do:

create type dbo.Phone from nvarchar(25) null

Then you can do:

create table Contact (id int identity(1,1), name nvarchar(255), phone dbo.Phone)

You can see that a column of type Phone is an nvarchar(25) null column by default. You can use this for shorthand if you have lots of tables or you'd like to have one way to change all Phone columns at once. It's a practice--not really a "best" practice unless it's in some special cases.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top