Thursday, March 29, 2012

delete data from a field in a table

Hi,
I am trying to delete data from a field in my table, I want to clear all the
data from one field in my table (assuming the table is Students and the
field is firstName)
Thank you in advance.
LamyDo you want to set the column to NULL or an empty string? In any case, it is
a simple UPDATE
statements:
UPDATE tblname
SET colname = NULL
or
UPDATE tblname
SET colname = ''
Note that both above will modify all rows. Add a WHERE clause of you want to
limit.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Lamy" <lamine_d@.mpt-ltd.com> wrote in message news:%23Y0CLe2dHHA.2088@.TK2MSFTNGP05.phx.gbl.
.
> Hi,
> I am trying to delete data from a field in my table, I want to clear all t
he data from one field
> in my table (assuming the table is Students and the field is firstName)
> Thank you in advance.
> Lamy
>|||If the column you need to delete is nullable, you simply can:
UPDATE Students
SET firstName = NULL
If the column isn't nullable you could
UPDATE Students
SET firstName = expression | DEFAULT
if some default is defined you can use it; expression is any expression
resulting in an empty field. Remember that NULL is different from "empty" or
blank.
Gilberto
"Lamy" wrote:

> Hi,
> I am trying to delete data from a field in my table, I want to clear all t
he
> data from one field in my table (assuming the table is Students and the
> field is firstName)
> Thank you in advance.
> Lamy
>
>|||Dear Tibor and Gilberto,
Silly me.
Many thanks guys.
Regards
Lamine
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OOru0t2dHHA.4384@.TK2MSFTNGP03.phx.gbl...
> Do you want to set the column to NULL or an empty string? In any case, it
> is a simple UPDATE statements:
> UPDATE tblname
> SET colname = NULL
> or
> UPDATE tblname
> SET colname = ''
> Note that both above will modify all rows. Add a WHERE clause of you want
> to limit.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "Lamy" <lamine_d@.mpt-ltd.com> wrote in message
> news:%23Y0CLe2dHHA.2088@.TK2MSFTNGP05.phx.gbl...
>

No comments:

Post a Comment