Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Default value: ISNULL()
Hi!

I'm wondering whether it's possible to set up the MS SQL function
ISNULL() as a default value to avoid NULL entries when importing data
into a table?!

For example, I want the column1, to have a 0 (zero) as default value,
when entering/importing data: isnull("column1",0)

I remember that it is possible to set up with a date function like
now(), having for each record the current time as default value. Is
that also with isnull() somehow possible?

Thx a lot!
Peter


Report this thread to moderator Post Follow-up to this message
Old Post
Peter Neumaier
01-23-06 12:23 PM


Re: Default value: ISNULL()
You can create a default constraint to specify a default value for a column.
For example:

CREATE TABLE MyTable
(
Col1 int NOT NULL,
Col2 int NULL
CONSTRAINT DF_MyTable_Col1 DEFAULT 0
)
GO
INSERT INTO MyTable (Col1) VALUES(1)
SELECT * FROM MyTable
GO

However, an explicit NULL will override the default constraint value:

INSERT INTO MyTable (Col1, Col2) VALUES(2, NULL)
SELECT * FROM MyTable
GO

If you need to import data containing a mix of nulls and not nulls, you have
options depending on your data source and import tool.  In the case of a
query, you could use ISNULL or COALESCE to specify the desired value when
NULL.  With DTS, a column transformation could do the job.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Peter Neumaier" <Peter.Neumaier@gmail.com> wrote in message
news:1138013760.433105.245790@g43g2000cwa.googlegroups.com...
> Hi!
>
> I'm wondering whether it's possible to set up the MS SQL function
> ISNULL() as a default value to avoid NULL entries when importing data
> into a table?!
>
> For example, I want the column1, to have a 0 (zero) as default value,
> when entering/importing data: isnull("column1",0)
>
> I remember that it is possible to set up with a date function like
> now(), having for each record the current time as default value. Is
> that also with isnull() somehow possible?
>
> Thx a lot!
> Peter
>



Report this thread to moderator Post Follow-up to this message
Old Post
Dan Guzman
01-23-06 12:23 PM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 04:02 AM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006