0
CREATE TABLE [selected_parameters]
([provider_id] NVARCHAR(100) NOT NULL,
   [parameter_id] NVARCHAR(100) NOT NULL,
   [parameter_name] NVARCHAR(100),
   [selected] BIT DEFAULT 0,
   [type] NVARCHAR(30)
);
ALTER TABLE [selected_parameters] ADD CONSTRAINT [PK__selected_parameters__00000000000000BA] PRIMARY KEY ([provider_id], [parameter_id]);

How can I drop primary key in SQL CE 3.5 with out knowing it name ?

  • 1
    [Get the primary key name](https://stackoverflow.com/questions/3930338/sql-server-get-table-primary-key-using-sql-query), write dynamic SQL to drop the primary key (`ALTER TABLE DROP CONSTRAINT `) and [execute](https://msdn.microsoft.com/en-us/library/ms188001.aspx) that dynamic SQL. – TT. Jan 14 '16 at 10:00
  • I can get primary key name by: `SELECT TOP(1) CONSTRAINT_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = 'selected_parameters'` but in sql compact(ce) i can't declare variables to pass to execute, I can do that in program but I would like to do that only in sql ce – Grzegorz K. Jan 14 '16 at 10:17
  • To prevent this situation in the first place, ALWAYS name your constraints yourself. – TT. Jan 14 '16 at 10:26
  • This question was already asked on SO [here](https://stackoverflow.com/questions/24879338/sql-ce-dynamic-query). The conclusion was that you can only do this from code (see comments). And remember to ALWAYS name your constraints to prevent this situation in the future. – TT. Jan 14 '16 at 10:33
  • I always do that but some one else forget to do that and I have to clean up that mess. Ok, thanks I do that from code – Grzegorz K. Jan 14 '16 at 10:34

0 Answers0