Delete the attributes value - oracle10g

How to delete the attributes value of a table in oracle 10g using sql command?
Example of problem like: Delete the email_id of employee James.-> I tried this code
DELETE FROM EMPLOYEE01 WHERE MAIL_ID= 'james#gmail.com'
but after run output showed me that entire row was deleted but I want only email id delete from particular row.

If you only want to update a row, use UPDATE:
UPDATE EMPLOYEE01
SET MAIL_ID = NULL
WHERE MAIL_ID = 'james#gmail.com'
Here, SET MAIL_ID = NULL will remove the value from MAIL_ID field for the record identified by the WHERE clause.

Related

Update the value for DB2 varchar for bit data column

In a DB2 database ,I have a table with a column of data type 'varchar for bit data'. I want to update a record in this table, and set a value for this column. When I updated the record , I see a different value for this column than the value I set in the update statement. The value I want to update in this column is '895623'. Which value do I use in my update statement to achieve this? What would be the update statement for this in DB2?

ignite delete row issue

I create a table user(_key(user_id,type),user_id(int),type(string),name(string), and had row,(1,"2","Scott") , then I update the row values to (2,"2","admin").and then delete the row delete from user where user_id = 2 and type = "2",sql scripts executed successfully, but select * from user again, the row still there ,ignite version number 2.9.1.anybody has the issue.
Ignite doesn't support a primary key modification. As result, you're not able to change the "user_id" value since it's a part of the PK. As a workaround, you can remove the existing row and insert a new one with the updated value.

Postgres select & delete where command did not returns empty while the row exists

I'm currently writing an app that has a need to remove a row from a table
I have a junction table where a row has 2 foreign keys, to test them, i tried to hardcode a row (the test one) then tried to post them using pg. hence theres 2 rows.
I tried to delete using pg with the line
DELETE FROM playlistsongs WHERE playlist_id = $1 AND song_id = $2 RETURNING id
pg returns not found. So out of curiousity, I tried to select the row from the command line. and It returns this
Are there any explanation why the query did not found any data? And how would I delete the row?
Thanks in advance!

SQL function to read null fields and update with a string value

I have an insert that is recording data from a webform and inserting it into my table. I'd like to run an update immediately after my insert that reads the previous insert and finds all the null fields and updates that record's null fields with a string of --
The data-type for all my fields is varchar
I have 20+ forms each with 100+ fields so i'm looking for a function that would be smart enough to read/update the fields that have null values without specifically enumerating/writing out each field for the update statement. This would just take way too long.
Does anyone know of a way to read simply which fields have null values and update any fields that are null to a string, in my case --
IF you can't alter your existing code,I would go with insert trigger...so after every insert,you can check and see the null values and update them like below
create trigger triggername
on table
after insert
as
begin
update t
set t.col1=isnull(i.col1,'--'),
t.col2=isnull(i.col2,'--')
rest of cols
from table t
join
inserted i
on i.matchingcol=t.mtachingcol
end
The issue with above approach is,you will have to check all inserted rows..I would go with this approach only,since filtering many cols with many or clauses is not good for performance
If is to just for display purposes,i would go with view
Instead of update after insert you may try changing table structure.
Set default value of the columns to --. If while insert no value is provided, -- will be inserted automatically.

Prevent insertion if the records already exist in sqlite

I am programming for iPhone and i am using SQLITE DB for my app.I have a situation where i want to insert records into the table,only if the records doesn't exist previously.Otherwise the records should not get inserted.
How can i do this?Please any body suggest me a suitable query for this.
Thank you one and all,
Looking at SQLite's INSERT page http://www.sqlite.org/lang_insert.html.
You can do it using the following syntax
INSERT OR IGNORE INTO tablename ....
Example
INSERT OR IGNORE INTO tablename(id, value, data) VALUES(2, 4562, 'Sample Data');
Note : You need to have a KEY on the table columns which uniquely identify a row. It is only if a duplicate KEY is tried to be inserted that INSERT OR IGNORE will not insert a new row.
In the above example if you have a KEY on id, then another row with id = 2 will not be inserted.
If you have a KEY only on id and value then a combination of id = 2 and value = 4562 will cause a new row not be inserted.
In short there must be a key to uniquely identify a ROW only then will the Database know there is a duplicate which SHOULD NOT Be allowed.
Otherwise if you do not have a KEY you would need to go the SELECT and then check if a row is already there, route. But here also whichever condition you are using on columns you can add them as a KEY to the table and simply use the INSERT OR IGNORE
In SQLite it is not possible to ALTER the table and add a constraint like UNIQUE or PRIMAY KEY. For that you need to recreate the table. Look at this FAQ on sqlite.org
http://sqlite.org/faq.html#q11
Hello Sankar what you can do is perform a select query with the record you wish to insert and then check the response via SQLite's SQLITE_NOTFOUND flag you can check whether that record already exists or not. If it doesn't exist you can insert it otherwise you skip inserting.
I hope this is helpful.