Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 10th, 2005, 02:38 PM
torstenzey torstenzey is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 7 torstenzey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 21 sec
Reputation Power: 0
Question how to alter primary key column?

Hi!

I’ve got problems to alter a column witch is a primary key.
I want to change a column from VARCHAR(50) to VARCHAR(100)

This works only with non primary key columns:
ALTER TABLE table ALTER COLUMN column TYPE VARCHAR(100)

Can someone give me a example to do that?

Thanks!
Torsten

Reply With Quote
  #2  
Old May 11th, 2005, 02:39 AM
SilverDB's Avatar
SilverDB SilverDB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Romania
Posts: 173 SilverDB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 45 m 53 sec
Reputation Power: 5
Send a message via Yahoo to SilverDB
Thumbs up

well ... first of all ... i think you should consider using an integer primary key.
Code:
CREATE TABLE ..... (ID INTEGER NOT NULL PRIMARY KEY ...........)


anyway ... to modify the primary key you must drop the constraints related to the primary key (not null, primary key) drop the index (RDB$PRIMARY...) and then you are left with a normal column which you can alter the way you want it.
__________________
If i've been helpful, please add to my reputation.
My unfinished site: http://www.dever.ro

Reply With Quote
  #3  
Old May 11th, 2005, 11:32 AM
torstenzey torstenzey is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 7 torstenzey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 21 sec
Reputation Power: 0
Unhappy

Thanks for your answer

But I’m not able to drop column constraints!

I’ve tried a lot of things – for example this:
ALTER TABLE table ALTER COLUMN column DROP CONSTRAINT PRIMARY KEY

But nothing worked!

Reply With Quote
  #4  
Old May 12th, 2005, 01:10 AM
SilverDB's Avatar
SilverDB SilverDB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Romania
Posts: 173 SilverDB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 45 m 53 sec
Reputation Power: 5
Send a message via Yahoo to SilverDB
The correct sql would be something like:
(this is a real example)
(the primary key constraint)
Code:
ALTER TABLE TEST DROP CONSTRAINT INTEG_23

(the not null constraint)
Code:
ALTER TABLE TEST DROP CONSTRAINT INTEG_18

after that you can alter your column:
Code:
ALTER TABLE table ALTER column ....

Reply With Quote
  #5  
Old May 12th, 2005, 02:31 PM
torstenzey torstenzey is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 7 torstenzey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 21 sec
Reputation Power: 0
Lightbulb

Thanks again!

But the problem is – the constraint changes always.
In my case, it’s INTEG_47!

Now I’ve found a way to delete a PRIMARY KEY.
But it takes two steps:
select rdb$constraint_name from rdb$relation_constraints where rdb$constraint_type='PRIMARY KEY' and rdb$relation_name='tablename';
ALTER TABLE tablename DROP CONSTRAINT <result of selection>;

Why isn’t it possible, just to say DROP PRIMARY KEY ?

Sincerely Torsten

Reply With Quote
  #6  
Old May 12th, 2005, 03:49 PM
shammat shammat is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2003
Location: Munich, Bavaria
Posts: 1,007 shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 13 h 20 m 10 sec
Reputation Power: 67
Why don't you simply give your primary key a name?
Code:
CREATE TABLE foo 
( 
  id integer
...
);
ALTER TABLE foo
  ADD CONSTRAINT foo_pk PRIMARY KEY (id);

Reply With Quote
  #7  
Old May 13th, 2005, 03:27 AM
SilverDB's Avatar
SilverDB SilverDB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Romania
Posts: 173 SilverDB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 45 m 53 sec
Reputation Power: 5
Send a message via Yahoo to SilverDB
Quote:
Originally Posted by torstenzey
...
Why isn’t it possible, just to say DROP PRIMARY KEY ?
...


In my opinion you should have no reasons to delete a PRIMARY KEY especially when that is a FOREIGN KEY in another table and it is set by a GENERATOR !
What you have now is a perfect example of a bad database design in the first place

Reply With Quote
  #8  
Old May 16th, 2005, 07:19 AM
torstenzey torstenzey is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 7 torstenzey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 21 sec
Reputation Power: 0
Quote:
Originally Posted by SilverDB
In my opinion you should have no reasons to delete a PRIMARY KEY especially when that is a FOREIGN KEY in another table and it is set by a GENERATOR !
What you have now is a perfect example of a bad database design in the first place


@SilverDB:
Haha!
Please look at the top of the thread.
I don't want to delete the primary key at all!

@shammat:
Thanks! I will try that!

Reply With Quote
  #9  
Old July 30th, 2008, 11:03 PM
artie75_abra artie75_abra is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Location: BAGUIO CITY PHILIPPINES
Posts: 1 artie75_abra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 24 sec
Reputation Power: 0
Send a message via MSN to artie75_abra Send a message via Yahoo to artie75_abra Send a message via Google Talk to artie75_abra Send a message via Skype to artie75_abra
Erase Rdb$relation Constraints Failed Action Cancenceld By Trigger (1)

Quote:
Originally Posted by SilverDB
The correct sql would be something like:
(this is a real example)
(the primary key constraint)
Code:
ALTER TABLE TEST DROP CONSTRAINT INTEG_23

(the not null constraint)
Code:
ALTER TABLE TEST DROP CONSTRAINT INTEG_18

after that you can alter your column:
Code:
ALTER TABLE table ALTER column ....


Hi!

Im trying to drop the constraints of my primarykey but the error ERASE RDB$RELATION CONSTRAINTS FAILED ACTION CANCENCELD BY TRIGGER (1) TO PRESERVE DATA INTEGRITY
I tried to look for the trigger in the other tables and but i cant find any that uses my primary key (ID_NO).

Where can i find the trigger? Please help...

Reply With Quote
  #10  
Old August 1st, 2008, 04:46 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 818 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 51 m 6 sec
Reputation Power: 19
Quote:
Where can i find the trigger? Please help...

It is not thee trigger you should be looking for.
It is the Foreign Key constraint linked to your PK.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > how to alter primary key column?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT