?
Solved

Retrieving Default Value of a Field using T-SQL

Posted on 2007-04-09
2
Medium Priority
?
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 18878303
0
 
LVL 10

Assisted Solution

by:ksaul
ksaul earned 1000 total points
ID: 18878377
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 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

762 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