SQL server managment studio, how to clear data from one column only

SQL server managment studio, how to clear data from one column only. I manage my database tables on my server with SQL server managment studio. I need to clear the data from a column without deleting that column. I'm a novice  with databases and this SQL server managment studio.
Who is Participating?
Tim HumphriesConnect With a Mentor DirectorCommented:
It depends on how your table is ordered in the list. If you do not have sequential numbers beginning at 1 (without any gaps) then the above will not work.

So, first determine what field you want to order the results by. Then you can use the row_number() function to identify the rows to be deleted.

    select *, row_number() over (order by <your field>) as rownum
	from <your table>
SELECT * -- better select first to check, before you delete!
FROM tab 
WHERE rownum BETWEEN 25 and 75

Open in new window

Om PrakashCommented:
You cannot delete column data from SQL management studio, but you can write simple SQL query to do so:

UPDATE your_table SET your_field = ''
This will set all the data in your_field as blank.
Tim HumphriesDirectorCommented:
Above will work if the column is text, but it would be better to ensure that the field allows nulls (set this in management studio) and then set the column to null:

UPDATE your_table SET your_field = null
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

Rob099Author Commented:
Can I also add another instruction to the query to apply that clear column only from rows 25 to 75.  
Om PrakashCommented:
-- Add where condition
UPDATE your_table SET your_field = ''  WHERE your_field_id between 25 and 75
--Assuming your_field_id is the primary key column as integer and contains sequential numbers.
Tim HumphriesDirectorCommented:
I meant updated, not deleted, of course...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.