Questions tagged [column-defaults]
20 questions
21
votes
10 answers
Should a database table have default values?
I was having a discussion with a developer at work on the issue of should a table use default values. Is there a hard and fast rule on this or is it a gray area in best practices?

Todd Moses
- 10,969
- 10
- 47
- 65
6
votes
4 answers
Is there a way to conditionally use default column values in an INSERT..SELECT statement?
I've got code similar to the following in a stored procedure that inserts a row into a table, I'd like to set the last column (FieldD) to @prmSomeValue unless it is null, otherwise just use the default value defined for that column.
IF…

JohnFx
- 34,542
- 18
- 104
- 162
6
votes
2 answers
FluentNHibernate - Setting default value for DB columns (SQL Server)
does anyone know a way how I could set through mapping the default value of a column so for e.g. when I generate DB from mappings I would have DateTime column having getdate() as default value?
I tried so far this (looks exactlly like what I need)…

Nikola Malovic
- 1,230
- 1
- 13
- 24
5
votes
7 answers
Adding a column with a Default value?
I am adding a column to my database table. It is a simple Char column with either a value of 'Y' or 'N'.
Is it possible to default the column to be 'N'? If so, how?
Current Script to add column:
ALTER TABLE PERSON
ADD IS_ACTIVE VARCHAR2(1);

java123999
- 6,974
- 36
- 77
- 121
4
votes
2 answers
SQL - Setting parameters for Default Column Value in Table
Using SQL Server 2012.
I have a column in my member table that is created using the following script:
[EnableMemberWebAccess] [bit] NOT NULL DEFAULT ((1))
I want this column to only have 1 as a default if another column in this same table is a…

BenW2811
- 81
- 6
4
votes
1 answer
Rename nextval('...') in Postgres
I had a table called pivot_device_user and had a sequence on the id as not null default nextval('pivot_device_user_id_seq'::regclass).
Then I decided to rename my table to pivot_box_user, but the nextval(...) is still…

Kousha
- 32,871
- 51
- 172
- 296
4
votes
1 answer
How to use column default in the where clause to identify default value
I am trying to write a query that tells if a column named s in table a.t has its default value (which is a very big base64 string). So I tried:
SELECT 1 FROM a.t WHERE s = (
SELECT column_default FROM information_schema.columns
WHERE…

user9645
- 6,286
- 6
- 29
- 43
3
votes
1 answer
Script to generate default values for not columns with no defaults specified in SQL Server
I have a MySQL database that I am migrating to SQL Server. The application that references the database breaks when I run it against SQL Server because SQL Server does not offer the implicit defaults that MySQL offers.
I wanted to see if there is a…

shikarishambu
- 2,219
- 6
- 35
- 57
2
votes
1 answer
INSERT ...RETURNING .. comes up empty when BEFORE trigger cancels statement
I have a PostgreSQL before insert trigger on create that basically redirects inserts into sub-tables. Once I insert the record, I want to ABORT the request as to avoid duplicate data (by not inserting into parent table) so I am using return NULL in…

Sarat Kiran
- 23
- 3
1
vote
1 answer
Postgres: how does a default value get populated?
To be clear, I want to know what is the mechanism that is used to populate the default value not the SQL syntax needed to create the default value constraint on the table.
Does Postgres use some kind of trigger that updates the default value if it…

shaffooo
- 1,478
- 23
- 28
1
vote
0 answers
angular-ui-grid up-down arrows not displaying for column of type number
When I set my column type to 'number', it does not render the default up/down arrows. It will only allow straight text editing. Is another grid option overriding it? The "Priority" column is the issue in my example.
Column with up/down arrows:
My…

Justin W
- 63
- 1
- 5
1
vote
1 answer
Grails 2.2.4: creating a column default value in MySQL 5.5
I followed the instructions that I found many places online for how, for a Grails 2.2.4 domain object property, to create a default value on its corresponding MySQL 5.5 column.
Unfortunately, the columns that are supposed to have a default value do…

XDR
- 4,070
- 3
- 30
- 54
1
vote
1 answer
Alter table add column default and execute the default for each row
I am making a function that adds a id column to a given table, creates a sequence and fills the new columns value. The thing is that the column is created but now I need to fill it with nextval() of the created sequence (1,2,3,4,5...). I don't know…

Egidi
- 1,736
- 8
- 43
- 69
0
votes
0 answers
Postgres alter multiple columns to citext type
We need to change 206 fields in multiple tables to data_type citext (extension). I've created the extension and manually changed a column to see what it should look like in the schema. The data_type needs to be USER-DEFINED and column_default needs…

Travis
- 31
- 3
0
votes
3 answers
How can I change_column_default based on the value selected of another row in a Ruby on Rails migration?
Sorry, y'all. New to Ruby on Rails.
I am updating a profile form that consists of the following YES/NO questions:
The user table already has an existing children_under_five column but I'd like to add a column has_children to incorporate whether…

sbuck89
- 123
- 3
- 6