title: Renaming Tables SQL Server, cascading that change through PK and FK's
body: <p>I want to find a sql command or something that can do this where I have a table named tblFoo and I want to name it tblFooBar. However, I want the primary key to also be change, for example, currently it is:</p>
  
  <pre><code>CONSTRAINT [PK_tblFoo] PRIMARY KEY CLUSTERED 
  </code></pre>
  
  <p>And I want a name change to change it to:</p>
  
  <pre><code>CONSTRAINT [PK_tblFooBar] PRIMARY KEY CLUSTERED 
  </code></pre>
  
  <p>Then, recursively go through and cascade this change on all tables that have a foreigh key relationship, eg. from this:</p>
  
  <pre><code>CHECK ADD  CONSTRAINT [FK_tblContent_tblFoo] FOREIGN KEY([fooID])
  </code></pre>
  
  <p>To this:</p>
  
  <pre><code> CHECK ADD  CONSTRAINT [FK_tblContent_tblFooBar] FOREIGN KEY([fooID])
  </code></pre>
  
  <p>Naturally, I am trying not to go through and do this all manually because a) it is an error prone process, and b)it doesn't scale.</p>