Solved

Retrieving Default Value of a Field using T-SQL

Posted on 2007-04-09
2
206 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 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

791 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