Thursday, March 29, 2012
delete data from a field in a table
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...
>
Friday, February 24, 2012
default value of the foreign key field in a child table
Foreign key field of the child table is not a required field. If the
data is submitted w/o a value into the foreign key field, what should
I make it as a default value? Should it be "null"?reneeccwest@.hotmail.com (reneeccwest) wrote in message news:<9f9d6d21.0310081243.7e44194d@.posting.google.com>...
> There are two tables, parent and child table.
> Foreign key field of the child table is not a required field. If the
> data is submitted w/o a value into the foreign key field, what should
> I make it as a default value? Should it be "null"?
If the column is NULLable, then NULL should be acceptable; if you need
to enforce a default value, that suggests you should probably have a
NOT NULL column with a DEFAULT constraint. So it depends on your data
model and business rules.
Simon|||Hi,
it MUST be NULL, otherwise you get a constraint violation; you can
define a default value but it have to be inserted on the master table.
Bye.
reneeccwest@.hotmail.com (reneeccwest) wrote in message news:<9f9d6d21.0310081243.7e44194d@.posting.google.com>...
> There are two tables, parent and child table.
> Foreign key field of the child table is not a required field. If the
> data is submitted w/o a value into the foreign key field, what should
> I make it as a default value? Should it be "null"?