[ACCEPTED]-Bind a column default value to a function in SQL 2005-default-value
Accepted answer
The syntax to add a default like that would 2 be
alter table DOC_Order
add constraint
df_DOC_Order
default([dbo].[NEWDOC_Order]())
for DOC_Order
Also, you might want to alter your function 1 to handle when DOC_Order is null
Create FUNCTION [dbo].[NEWDOC_Order]
(
)
RETURNS int
AS
BEGIN
RETURN (SELECT ISNULL(MAX(DOC_ORDER),0) + 1 FROM DOC_Documents)
END
IF someone wants to do it using the interface, typing 2
[dbo].[NEWDOC_Order]()
does the trick. You apparently need all 1 brackets or it will reject your input.
Here's screen shots to do it through SQL 3 Server Management Studio GUI:
- Right click on table and select
Design
- Select DOC_Order column (or other column needing default) in the table's design view to see properties
- Update
Default Value or Binding
with function name with brackets like so:
Note: as Luk 2 stated, all brackets are needed including 1 the schema (dbo in this case).
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.