¿Cómo agregar un valor predeterminado a una columna ya existente?
Tengo una columna existente en mi base de datos SQL Server. He intentado todo lo que se me ocurre, pero no puedo obtener un valor predeterminado para agregar a la columna. Lo que funciona en cualquier otra base de datos es
alter table mytable
alter column mycolumn set default(now()) --mycolumn is a datetime
¿Cómo hago esto en SQL Server?
El error que obtengo para esa sintaxis exacta es incorrect syntax near the keyword 'set'
32
Author: OMG Ponies, 2010-06-17
2 answers
Uso:
ALTER TABLE dbo.mytable
ADD CONSTRAINT def_mycolumn DEFAULT GETDATE() FOR mycolumn
Para obtener más información, consulte: Trabajar con restricciones predeterminadas
65
Author: OMG Ponies,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-06-17 00:18:13
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-06-17 00:18:13
Si desea cambiar el valor predeterminado de una columna existente. Primero debe soltar la restricción y luego agregar la restricción de nuevo como se muestra a continuación
ALTER TABLE <TABLE>
DROP CONSTRAINT <CONSTRAINT NAME>
ALTER TABLE <TABLE>
ADD CONSTRAINT <CONSTRAINT NAME> DEFAULT <VALUE> for <COLUMN>
Si no tiene los detalles de restricción de la tabla, puede usar la siguiente consulta
sp_helpconstraint <TABLE>
6
Author: suryakiran,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-05-04 12:27:18
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-05-04 12:27:18