SQLTeam.com | Weblogs | Forums

Create table default value from SP


#1

Hi All,

How can I get default value when create an table? I try to do this:-

alter table tblRes
add CountryID int not null default dbo.getCountrybyOffice(OfficeID)

My SP:

create procedure getCountrybyOffice
(
@OfficeID int
)
As
BEGIN
SELECT CountryID
FROM tblOffice
where OfficeID=@OfficeID

END

Please advise.

Thank you.

Regards,
Micheale


#2

You can't call a stored procedure while creating a table since Subqueries are not allowed while creating a table.
The default value for the column should be a scalar not expression.


#3

Also that will be applied to new rows added and will not update default values to the existing data