Questions tagged [default-constraint]
39 questions
86
votes
1 answer
Command for adding a default constraint
There appears to be at least two ways to add a default constraint using straight T-SQL. Am I correct that the only difference between the two below is that the second method specifically creates a name for the constraint, and the first method has…

Randy Minder
- 47,200
- 49
- 204
- 358
49
votes
1 answer
default a column with empty string
Is there a way, via a SQL statement, to ensure a column's default value is an empty string '' instead of NULL?

Sharpeye500
- 8,775
- 25
- 95
- 143
38
votes
2 answers
How to add a default value to an already existing column?
I have an existing column in my SQL Server database. I have tried about everything I can think of but can not get a default value to be added to the column. What works in every other database is
alter table mytable
alter column mycolumn set…

Earlz
- 62,085
- 98
- 303
- 499
29
votes
2 answers
What does the Alter Table syntax look like for adding a DATETIME column?
I can't find what the syntax looks like for adding a DATETIME column to a mysql table when I want to set the default to - example - 2011-01-26 14:30:00
Does anyone know what that syntax looks like?
Here's what I've got
ADD COLUMN new_date DATETIME…

H. Ferrence
- 7,906
- 31
- 98
- 161
26
votes
3 answers
How to get EF 6 to handle DEFAULT CONSTRAINT on a database during INSERT
I am new to EF (its my first week), but not new to databases or to programming. Others have asked similar questions, but I don't feel that it has been asked with the right detail or explained quite as it needs to be explained, so here I…

Mike Stillion
- 403
- 1
- 4
- 7
10
votes
2 answers
Why does adding a nullable default constraint to an existing column take so long?
I have an existing table with approximately 400 million rows. That table includes a set of bit columns named IsModified, IsDeleted, and IsExpired.
CREATE TABLE [dbo].[ActivityAccumulator](
[ActivityAccumulator_SK] [int] IDENTITY(1,1) NOT NULL,
…

AHiggins
- 7,029
- 6
- 36
- 54
8
votes
1 answer
EF core ,Create Custom Default Constraint Name
I am using EF core 2.1 and want to create custom default Constraint Name.
Currently, its getting create Constraint "DF__StudentBa__Admit__1DB06A4F"

user1453078
- 121
- 6
8
votes
3 answers
SqlBulkCopy into table that Default column values fails when source DataTable row has DBNull.Value
Update: Here is my solution
I have a table defined as:
CREATE TABLE [dbo].[csvrf_References]
(
[Ident] [int] IDENTITY(1,1) NOT NULL,
[ReferenceID] [uniqueidentifier] NOT NULL DEFAULT (newsequentialid()),
[Type] [nvarchar](255) NOT NULL,
…

James Nix
- 885
- 1
- 6
- 19
6
votes
3 answers
How to set another value on a boolean with defaut value with Entity Framework Core?
I got quite the same problem in this question :
How to override SQL Server default value constraint on a boolean when inserting new entity? [closed]
Like him, I get the good value of my boolean from the client to the controller, false, but it's set…

Korgoth
- 109
- 1
- 2
- 10
5
votes
2 answers
how to remove default constraint from column in Db2
I had a table STUDENT_TB, which had column STUDENT_ID, NAME, AGE. I added a column with a following command :-
alter table STUDENT_TB add DOB TIMESTAMP NOT NULL DEFAULT CURRENT TIMESTAMP
as for the DOB column i didn't wanted it to be null. Now i…

M.J.
- 16,266
- 28
- 75
- 97
5
votes
3 answers
Pass a NULL value to DateTime Field in LINQ
My database table is like this
CREATE TABLE MYBUDGET.tbl_CurrentProperty
(
[PropID] INT NOT NULL IDENTITY(1,1),
[UpdatedOn] DATETIME NOT NULL,
[Amount] MONEY NOT NULL,
…

Sency
- 2,818
- 8
- 42
- 59
4
votes
5 answers
Getting C# To Insert Defaults Into SQL Server
How can I INSERT values into SQL Server that are stored in a string[] such that some of the values should be disregarded in favor of the values stored in SQL Server as default constraints on the table? What do I need to pass(e.g. NULL or something…

Ian Best
- 510
- 1
- 11
- 23
3
votes
1 answer
Orphan constraints in SQL Server database
Running the following query results in all constraints in our client's database. However, several rows in the result set don't seem to have a parent, i.e. parent_object_id = 0 and OBJECT_NAME(parent_object_id) returns NULL.
SELECT name, type_desc,…

bernhof
- 6,219
- 2
- 45
- 71
3
votes
2 answers
Get the value from a default constraint
I need to change a default constraint value from 0 to 1. This is done easy with:
ALTER TABLE table DROP CONSTRAINT X
ALTER TABLE table ADD CONSTRAINT X default (1) for table.column
The problem is that I don't want to drop and create a new…
user3025336
2
votes
1 answer
Stored procedure with parameter that defaults to default constraint value
I have a Users table that has an ImgPath column. I want that ImgPath column to be not null and default to a specific path. In the table declaration, I have this:
[ImgPath] VARCHAR(256) NOT NULL
CONSTRAINT [DF_Users_ImgPath] DEFAULT…

ScubaSteve
- 7,724
- 8
- 52
- 65