Solved

delete a column from a table in SQL

Posted on 1998-06-24
6
562 Views
Last Modified: 2012-05-07
I don't remember the SQL syntax for delete a column !
0
Comment
Question by:verly
6 Comments
 
LVL 7

Accepted Solution

by:
spiridonov earned 50 total points
ID: 1091615
There is NO SQL syntax to delete a column from SQL Server table. The only way to do it is:
1. Rename Table
2.  Create new table with one column less
3. Insert data from renamed table into new table
4 Drop renamed table.
use IDENTITY_INSERT  ON/OFF if you inserting data into table with IDENITY column
0
 

Author Comment

by:verly
ID: 1091616
40 points because your response arrived fast !
0
 
LVL 1

Expert Comment

by:josephfluckiger
ID: 9889754
this appears to no longer be the case. Using Microsoft SQL server 2000. This statement worked for me:

ALTER TABLE MyTable DROP MyColumn
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 34

Expert Comment

by:arbert
ID: 9900484
I like it when people accept stupid answers....
0
 
LVL 1

Expert Comment

by:josephfluckiger
ID: 9900500
:)
0
 
LVL 6

Expert Comment

by:JohnDesautels
ID: 12484028
joseph,

Your syntax didn't work for me.

I needed to use DROP COLUMN vs just DROP:

ALTER TABLE MyTable DROP COLUMN MyColumn

I found it at:

http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_21127678.html?query=delete+column+from+table&topics=42 

John
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question