Solved

Retrieving Default Value of a Field using T-SQL

Posted on 2007-04-09
2
174 Views
Last Modified: 2010-03-19
Is there a way of accessing the default value for a field from tSQL?

I relize you could clear a new record, check the value and then delete the record, but that seems an expensive way of doing it.

Creating a record default could work, but if you changed the default in the table then it would be wrong.

Any way of accessing the value directly?
0
Comment
Question by:randymiller
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
Comment Utility
0
 
LVL 10

Assisted Solution

by:ksaul
ksaul earned 250 total points
Comment Utility
SELECT c.name ColumnName,  com.text Default
FROM syscolumns c
INNER join sysobjects o on c.id = o.id
INNER join syscomments com on c.cdefault = com.id
WHERE o.name = 'YourTable' and c.name = 'YourColumn'
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now