How do we find columns that have default constraints

  • CREATE TABLE XYZ

    (

    ID int DEFAULT 5000,

    NAME VARCHAR(100)

    )

    I have many tables that have many columns with default values

    Is there a way to get a listing of

    TAB_NAME, COL_NAME, Data_type, Default_Value

  • Use the sys.default_constraints system view.

    SELECT d.name, OBJECT_NAME( d.parent_object_id) , COL_NAME(d.parent_object_id, d.parent_column_id)

    FROM sys.default_constraints d

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • based on some of your other posts, it looks like you are trying to script out a table definition.

    take a look at my procedure i wrote in this article and procedure, and grab the code you need from that:

    http://www.sqlservercentral.com/Forums/Topic751783-566-8.aspx

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply