Solved

Retrieving Default Value of a Field using T-SQL

Posted on 2007-04-09
2
212 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 250 total points
ID: 18878303
0
 
LVL 10

Assisted Solution

by:ksaul
ksaul earned 250 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Is there any Easy way to copy CSV to SQL Server using C# 3 101
CONVERT date time to a different time zone. 2 71
Change this SQL to get all nodes 3 40
SQL query 7 18
This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…

733 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