Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 346725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:12:14+00:00 2026-05-12T11:12:14+00:00

I want to lookup the default value of a column in my SQL2005 database.

  • 0

I want to lookup the default value of a column in my SQL2005 database. I only have the SQL server connection string, so I can only use the Sql library namespace (can’t use the Oledb GetSchema stuff). I know there is a GetSchema()… but how do I use it to get a column schema, and thus the default value? I can’t fillSchema on a datatable, because that doesn’t appear to fill the default value property. I can use “exec sp_columns ‘ADDRESS_MASTER'” and that returns default values, but they are not in a clean format… for example, one of my text column default comes back as “(N’test)”.

I also want to get column size… sp_columns seems to give me everything… but I don’t know how to decode the default values in all cases?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:12:15+00:00Added an answer on May 12, 2026 at 11:12 am

    Your problem here is the default value is an expression and it seems like you want it to just return a value such as ‘bob’ or 5.

    This pretty much falls over the moment you have GetDate() or call a custom function such as dbo.MyFunc(). At this point what should it return as the default value?

    As such the only reliable thing the sql server can do is return to you the expression it will use to generate the default value, you could run this through the sql server again to determine the result, ie:

    DECLARE @def nvarchar(max)
    
    SELECT @def = column_def FROM information_schema.columns
    WHERE table_name = 'ADDRESS' AND column_name = 'ADDRESS_MASTER'
    
    EXEC ('SELECT ' + @def)
    

    Of course, if the expression isn’t constant such as in the case of GetDate this will be incorrect by the time you come to insert actual data. Also it would cause problems if using a custom function with side-effects, but a custom function with side-effects used in a default I’d consider a problem already.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Dictionary called AvailableBoxes. I want to lookup a string in this
I have several 'lookup' fields in my models where I don't want nulls, but
want to know why String behaves like value type while using ==. String s1
want to have a Hyperlink-Button in a gridView in which I can display a
>> Question summary I want to implement a resettable, over-ridable, default cell value in
I have an Access database that I use for reporting. After I do the
I want to use connection pooling with Jetty 6 , but so far it
We have a bunch of services (EJBs) that we want to lookup using the
I'm writing a Java application like AIM where I want a lookup server to
I want to look up some properties from JNDI configured in glassfish v3 server.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.