I'm looking to write a delete query. Below is what I already came up with however I'm not sure if its correct and I worried that I might delete something that I shouldn't.
Delete from TABLE1
where DATE = 202002
This table contains 5 fields and I need all of the data to be deleted form this table only for this DATE that I have listed. I was also thinking of writing it this way (example below) and wasnt sure which one of the two is correct.
Delete field1, field2, field3, field4 field5 from TABLE1
where DATE = 202002
Please advise.
PS. I'm working in Test environment.
The first form is correct:
DELETE FROM YOUR_TABLE
WHERE SOME_FIELD = 'SOME VALUE'
You can't put field names after DELETE
because you're deleting an entire row, not just a few fields.
A couple things here are unclear, so let's start with the basics.
First, a delete query will delete records (rows) of information in which 0 or more conditions are met. If your date field is indeed integer-based, then the first query you wrote will work fine.
Your second statement will not work because delete statements work on records rather than columns. If you wanted to keep the record but eliminate the individual field data you could do something like this (note this is T-SQL syntax, but is likely close to Oracle's):
Update Table1 set
Field1 = Null,
Field2 = Null,
Field3 = Null,
Field4 = Null,
Field5 = Null
where
Date = 202002
You can use a UPDATE sentence instead DELETE (that delete data rows don't data columns) like:
UPDATE TABLE1 SET
field1 = NULL, field2 = NULL, field3 = NULL, field4 = NULL, field5 = NULL
WHERE DATE = 202002
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.