Questions tagged [default-value]
For questions relating to DBMS-supplied values that are generated when none are explicitly provided.
88
questions
7
votes
1
answer
6k
views
Cannot alter MYSQL Table (stuck in a invalid default value loop)
Some how I have 2 columns with incorrect default values.
Not sure how it got created in the first place as I imported the db from another source.
Problem now is, I cannot make any changes to the ...
5
votes
1
answer
4k
views
How to set column DEFAULT using value of a variable
In a script for setting up a database which uses random UUIDs for primary keys, I have:
CREATE TABLE alpha (id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), value INT);
CREATE TABLE beta (aref UUID ...
3
votes
1
answer
8k
views
How can I set TIMESTAMP's default to future date?
I know I can set default value with current timestamp like this
... DEFAULT CURRENT_TIMESTAMP
Is there any way to set the column with fixed amount of units based on current timestamp?
... DEFAULT ...
0
votes
1
answer
18k
views
Adding a default constraint in Oracle while altering a column
I'm new to Oracle. I need to port a SQL Server command to Oracle.
I want to alter a column to add a new constraint with a default value.
SQL Server command
ALTER TABLE <schema_name>.<...
3
votes
1
answer
3k
views
Why are Column Defaults on my User-Defined Table Type (UDTT) not being honored?
I create a table type in SQL:
CREATE TYPE [dbo].[MyObject_TableType] AS TABLE
(
[Name] VARCHAR(MAX) DEFAULT '',
[Index] VARCHAR(MAX) DEFAULT ''
)
I build a DataTable and populate it with one ...
1
vote
2
answers
14k
views
How to set TIMESTAMP default value to 1970-01-01 00:00:01 UTC?
How can I set the default value for a TIMESTAMP column to be exactly 1970-01-01 00:00:01 UTC without changing time_zone?
I tried the following:
CREATE TABLE `foo` (`ts` TIMESTAMP DEFAULT CONVERT_TZ(
...
25
votes
2
answers
194k
views
Can't default date to CURRENT_TIMESTAMP in MySQL 5.5
I am not able to set Current_timestamp as default value. My Mysql version is 5.5.47.
Query is
ALTER TABLE `downloads` ADD `date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ;
While it is working ...
11
votes
3
answers
25k
views
Return the uniqueidentifier generated by a default on insert
Goal
Retrieve the latest guid value in real time after you have inserted the value in the table
Problem
Don't know how to do it
Info
The code should only specify new values for address and zipcode
...
131
votes
3
answers
226k
views
Default value for UUID column in Postgres
In Postgres 9.x, for a column of type UUID, how do I specify a UUID to be generated automatically as a default value for any row insert?
15
votes
3
answers
25k
views
Duplicate row with Primary Key in PostgreSQL
Assume I have a table as follows named people, where id is a Primary Key:
+-----------+---------+---------+
| id | fname | lname |
| (integer) | (text) | (text) |
+===========+=========+=...
0
votes
1
answer
4k
views
Using default values in primary key
Good day.
I have a table like this:
CREATE TABLE mytable (
myname varchar(30),
mydate date DEFAULT CURRENT_DATE,
PRIMARY KEY(myname, mydate)
);
EDIT:
Forgot to mention I am using a view ...
0
votes
1
answer
50
views
Assign value to a field after checking a condition
I have this query:
ALTER TABLE MERCHANTS
ADD COLUMN merchant_image bytea,
ADD COLUMN merchant_logo bytea,
ADD COLUMN merchant_address VARCHAR(100),
ADD COLUMN merchant_phone VARCHAR(50),
...
5
votes
2
answers
9k
views
Default value for "microtime" column in MySQL
My interest is to store the time with FSP of 6. As I've read, this cannot be achieved with TIMESTAMP or DATETIME data types. So, I have a double field to store the output of the microtime function.
...
1
vote
2
answers
4k
views
MYSQL find if a default value has been set for a table (DateTime Specifically)
I am trying to internationalize a database, but there are places where the timestamp that gets set is using NOW() instead of UTC_TIMESTAMP(), and it's using Amazon's RDS with multiple MySQL servers. ...
1
vote
0
answers
119
views
How to pass the value of PK to FK
Ok, so here it goes. I have a table called employee. then I have another table called languages. I need to copy the value of PK of employee table to foreign key in Languages table, rather than ...
1
vote
1
answer
3k
views
Foreign key default value
I have a master table and another table with foreign key. I can easily add data to master table. But whenever I want to add data to the connected table, I get a message saying Foreign key doesn't have ...
5
votes
2
answers
4k
views
Reg: Default Privileges on PostgreSQL Schemas
I have a situation where many users can create database objects across all the available schema.
There is a generic user pg_dump_user used for by all the developers to dump the whole database to ...
1
vote
0
answers
44
views
Uninitialized values: ignore or set?
From the implementation point of view for a database, is it preferable to handle optional form fields by setting to some default value (e.g. false, 0, "", etc.) or just ignore such fields (do nothing ...
1
vote
2
answers
775
views
Default constraint issue
I have a table TempTable with one column having a default constraint
ALTER TABLE [dbo].[TempTable]
ADD CONSTRAINT [DF_TempTable_Version]
DEFAULT ((1)) FOR [Version]
Version is defined as decimal ...
0
votes
1
answer
2k
views
Create a default value for session valid_until MySQL
Server version: 5.6.22 Homebrew
The table:
CREATE TABLE `sessions` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) unsigned NOT NULL,
`date_created` datetime ...
17
votes
2
answers
19k
views
Is there a way to insert multiple rows into a table with default values for all columns?
I can insert multiple rows into a table with default values for all columns the RBAR way:
create table course(course_id serial primary key);
do $$
begin
for i in 1..100000 loop
insert into ...
1
vote
0
answers
31
views
PostreSQL execute a default query when no row are returned [duplicate]
I need to calculate the average score of a list of userId.
I have a table "user_place_score" (user_id / place_id/ score).
Sometimes I do not have the score for a user_id so I need to fetch a "...
2
votes
3
answers
4k
views
PostgreSQL execute a default query when no row are returned
I need to calculate the average score of a list of userId.
I have a table user_place_score:
(user_id, place_id, score)
Sometimes I do not have the score (no row for (user_id,place_id) in the table) ...
0
votes
2
answers
311
views
In SQL Server what is the database cost for setting a default value on table that already has over 1mil records?
NOTE: I am not a dba. :)
I have a database table that a client needs to set a column's default value. This table has 1.5mil+ records in it and this column is already populated on all existing records ...
1
vote
1
answer
123
views
SQL Server - Is it possible to forbid creation of default constraint name?
I was having a looking on this article about default constraints and I have a question. Is there a configuration in SQL Server 2008 that forbid naming creation of new default constraints declared ...
3
votes
2
answers
13k
views
Why is add timestamp column with default not null so slow in Oracle 11g?
In Oracle I need to add a new column with type timestamp with time zone to a large table (80 million rows).
I cannot have more than 30 - 60 seconds of downtime when I run it in production.
This ...
2
votes
1
answer
146
views
Confused on how a value gets added with the DEFAULT constraint
A recent definition I've read about Default Constraints:
DEFAULT is specified for a column to assign a column a specific value if no value is specified when a row is added.
I believe I've seen code ...
0
votes
1
answer
356
views
Why is column default value not portable through different RDBMS?
Some ORMs (doctrine) do not support default values in database schema definition, because they states it is not portable.
But SQL92 supports the DEFAULT value clause, and all the databases supported ...
11
votes
3
answers
53k
views
SQL set allowed values for a column
I want to make an ALTER TABLE expression which adds a new column and sets a default value and additionaly defines the allowed values for that column. It's a text column, and allowed should be only '...
18
votes
2
answers
24k
views
How to create column in DB with default value random string
Can I create column in DB table (PostgreSQL) which have default value random string, and how ?
If is not possible, please let me know that.
2
votes
1
answer
5k
views
alter table (mysql) adding column with default value of space (' ')
On my Mac, using 5.5.11 MySQL Community Server (GPL)
alter table foobaz add column (
extendedTitle varchar(3000) DEFAULT NULL,
clasindxIndent int,
spacedash1 enum (' ', '-', '1') default ' ',
...
6
votes
1
answer
259
views
Find out which columns must be specified in insert-statement
Sometimes when inserting data in a table with many columns it could be useful to know which columns must be specified if the insert-statement shouldn't fail.
I wrote this query to find out which ...
3
votes
1
answer
2k
views
How can I get MySQL to use the value returned by a function as a default?
I have a pre-existing table that has a column to that can hold a UUID.
I'd like to be able to define a default such that new rows coming in (from legacy systems) will still get a UUID defined, via ...
19
votes
2
answers
4k
views
Why can't I use NEWSEQUENTIALID() as the default value for my column?
I'm trying to create a table in Management Studio and after reading about the new (from SQL 2005 on) NEWSEQUENTIALID() function, thought I'd give it a go.
This is what I'm doing:
But it's not ...
4
votes
1
answer
1k
views
An alternative for sp_unbinddefault
I have a column with default value bound to UW_ZeroDefault and I am trying get rid of it.
As I understand it, this default has been created by using CREATE DEFAULT then the column has been bound to ...
3
votes
2
answers
5k
views
How to set addtime(current_timestamp, '15:00:00') as MySQL timestamp column default value?
I want to set addtime(current_timestamp, '15:00:00') as the default value of one MySQL table column. I tried to do this with the following command but failed:
mysql> alter table mytable change c1 ...
13
votes
1
answer
40k
views
Add DEFAULT to existing column
In Microsoft SQL server, how can I add/change the default on an existing table column using T-SQL?
53
votes
5
answers
141k
views
How can I use a default value in a Select query in PostgreSQL?
I would like to use a default value for a column that should be used if no rows is returned. Is that possible in PostgreSQL? How can I do it? Or is there any other way I can solve this?
E.g. ...