Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SqlServer: How to drop a column with a randomly named (default) constraint?

SqlServer: How to drop a column with a randomly named (default) constraint?

Scheduled Pinned Locked Moved Database
helpdatabasetoolstutorialquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Super Lloyd
    wrote on last edited by
    #1

    I created a table in SqlServer with CREATE TABLE Foo( column1 bit not null default 0, ..... ) this implicitly created a randomly named constraint which would set the default value. Now when I try to run ALTER TABLE Foo DROP COLUM column1 I got the error message DF_Foo_colum_2F34CDE is dependent on column1, i.e. the randomly named constraint which sets the default value prevent the deletion of the column. Now I could fix that on my database, but how could I write a script which will work on all databases?

    A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

    S 1 Reply Last reply
    0
    • S Super Lloyd

      I created a table in SqlServer with CREATE TABLE Foo( column1 bit not null default 0, ..... ) this implicitly created a randomly named constraint which would set the default value. Now when I try to run ALTER TABLE Foo DROP COLUM column1 I got the error message DF_Foo_colum_2F34CDE is dependent on column1, i.e. the randomly named constraint which sets the default value prevent the deletion of the column. Now I could fix that on my database, but how could I write a script which will work on all databases?

      A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

      S Offline
      S Offline
      Super Lloyd
      wrote on last edited by
      #2

      I found out how to find those bastards! SELECT * FROM sys.sysobjects Where NAME LIKE 'DF__Foo%' or SELECT * FROM sys.objects type_desc='DEFAULT_CONSTRAINT' But I also had a better work around: :-D 1. these nameless constraints being only on developers machines so far, I just dropped them manually 2. and give them a name in the create table with CREATE TABLE FOO ( column1 bit not null CONSTRAINT DF_Foo_column1 DEFAULT 0 .... )

      A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups