0

I want to alter my table and drop a column which i know there is no data in it(because I just created it) now I want to delete it and it says

"SQL Error (3727): Could not drop constraint. See previous errors."

I use the following code:

    ALTER TABLE Object DROP WAddress
8
  • See previous errors. Commented Jun 21, 2017 at 5:32
  • Is that column linked to some different table Commented Jun 21, 2017 at 5:32
  • there is no previous error @NEER Commented Jun 21, 2017 at 5:32
  • no it's not linked to any thing @RohanKawade Commented Jun 21, 2017 at 5:33
  • Try ALTER TABLE Object DROP COLUMN WAddress? In other words, aren't you missing the "COLUMN" keyword? Commented Jun 21, 2017 at 5:34

2 Answers 2

6

Your query is missing the "COLUMN" keyword. Use:

ALTER TABLE Object DROP COLUMN WAddress

The reason it was throwing the error about the constraint, is that it was expecting that WAddress was the name of a constraint on the table because the keyword "COLUMN" was missing.

Sign up to request clarification or add additional context in comments.

Comments

3

Below are the syntax to drop column(s) from table:
Drop single column:

ALTER TABLE table_name DROP COLUMN column_name;

Drop multiple columns for SQL Server:

ALTER TABLE table_name DROP COLUMN (column_name1, column_name2);

For Oracle:

ALTER TABLE table_name DROP (column_name1, column_name2);

In your case you want to drop a single column so COLUMN keyword is required after DROP.
If you want to drop multiple columns, you can omit COLUMN keyword based on DB that you are using.

2 Comments

I think for multiple columns, your syntax won't work. It should be ALTER TABLE table_name DROP COLUMN column_name1, column_name2;
PratikPatel is right, try: CREATE TABLE #Object ( [a] INTEGER ,[b] INTEGER ,[c] INTEGER ) ALTER TABLE [#Object] DROP COLUMN a,b

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.