Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Primary Key in ALTER TABLE 1

Status
Not open for further replies.

HellTel

Programmer
Oct 28, 2002
343
GB
Hi
Well I need to programatically change the datatype of some fields in a few tables. It won't let me because the field is a primary key.
Can I disable it in an ALTER TABLE statement somehow? I've searched around but can't see anything.
The code will become a stored procedure if it works.

Cheers
Tel Hope I helped / Thanks for helping
if ((Math.abs(x)<10&&Math.abs(y)<10) && (((parseInt(Math.abs(x).toString()+Math.abs(y).toString())-Math.abs(x)-Math.abs(y))%9)!=0)) {alert(&quot;I'm a monkey's uncle&quot;);}
 
To get rid of a primary key constraint:

alter table <tableName> drop constraint <constraintName>

You can get the constraint name by the query

select * from information_schema.table_constraints
where table_name = '<tableName>'
and schema_name = '<schemaName>'
and constraint_type = 'PRIMARY KEY'
 
Superb!
Thanks swampBoogie, a star for you!

And I managed to work out from that to create a primary key again, I need

alter table <tableName> add constraint <constraintName> PRIMARY KEY(<columnName>)

so that should be me sorted.

Cheers Hope I helped / Thanks for helping
if ((Math.abs(x)<10&&Math.abs(y)<10) && (((parseInt(Math.abs(x).toString()+Math.abs(y).toString())-Math.abs(x)-Math.abs(y))%9)!=0)) {alert(&quot;I'm a monkey's uncle&quot;);}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top