sql-delete

How do I delete blank rows in Mysql?

北战南征 提交于 2019-12-21 04:15:29
问题 I do have a table with more than 100000 data elements, but there are almost 350 blank rows within. How do I delete this blank rows using phpmyadmin? Manually deleting is a tedious task. 回答1: The general answer is: DELETE FROM table_name WHERE some_column = ''; or DELETE FROM table_name WHERE some_column IS NULL; See: http://dev.mysql.com/doc/refman/5.0/en/delete.html More info when you post your tables!~ Also, be sure to do: SELECT * FROM table_name WHERE some_column = ''; before you delete,

Using return value from DELETE for UPDATE in Postgres

你离开我真会死。 提交于 2019-12-20 20:31:10
问题 I need to update a table using a value deleted from another table. The situation is a comment vote scorekeeper similar to the one on SO. I'm using python to work the postgres, but that shouldn't make a difference. query=""" UPDATE comment SET score=score-(DELETE FROM history WHERE commentId=%(commentId)s AND userIdentity=%(userIdentity)s RETURNING vote) WHERE commentId=%(commentId)s; """ cursor.execute(query, data) The error arises at (DELETE FROM ; a syntax error arises. I can replace the

SSIS - Delete rows

北慕城南 提交于 2019-12-20 10:53:13
问题 I'm new to SSIS and need help on this one. I found an article which describes how to detect rows which exist and which have changed. The part that I'm missing is how to update rows that changed. I found some articles which say that it's also good solution to delete records which have changed and insert new recordset. The thing is I don't know how to do that step of deleting (red box). Any suggestions? 回答1: If you have to delete the rows within Data Flow Task , then you need to use the OLE DB

How to programmatically check if row is deletable?

吃可爱长大的小学妹 提交于 2019-12-19 19:45:50
问题 Say we have a PostgreSQL table like so: CREATE TABLE master ( id INT PRIMARY KEY, ... ); and many other tables referencing it with foreign keys: CREATE TABLE other ( id INT PRIMARY KEY, id_master INT NOT NULL, ... CONSTRAINT other_id_master_fkey FOREIGN KEY (id_master) REFERENCES master (id) ON DELETE RESTRICT ); Is there a way to check (from within trigger function) if a master row is deletable without actually trying to delete it? The obvious way is to do a SELECT on all referencing tables

Leave only first 50 records in SQL database and delete the rest

为君一笑 提交于 2019-12-19 08:38:11
问题 I have a table of scores, which is made of 2 fields: name and high score . Something like this: ----------------------- | name | score | ----------------------- | John | 2450 | ----------------------- | Alice | 2420 | ----------------------- ... etc I need to delete all the rows till the top 50 scores. Is it possible without creating another temporary table ? 回答1: please try this delete from scores_tbl Where id not in (select * from (select id from scores_tbl order by score desc limit 50) as

How to Delete Records NOT IN

荒凉一梦 提交于 2019-12-19 06:21:30
问题 Hi I have the following SQL Query which gives me Scheme_Id which exist both in ProjectSchemes and Schemes table. I want to delete all records from Schemes table which have no record to ProjectSchemes table. How can I do so? Please help. I'm using MSSQL select scheme_id from Schemes where Scheme_Id in(select s.Scheme_Id from Projects p inner join ProjectSchemes ps on ps.Project_Id=p.Project_Id inner join Schemes s on s.Scheme_Id=ps.Scheme_Id) I'm trying to do the following but it's not working

Disable DELETE on table in PostgreSQL?

旧巷老猫 提交于 2019-12-18 12:13:09
问题 For a security sensitive design, I'd like to disable DELETEs on certain tables. The DELETE should merely set a deleted flag on a row (which would be then visible on a view, which would be used by the application layer). As I understand a rule would generate additional queries - so a rule could not suppress the original query. As illustration a toy example with a trigger (not yet tested): -- data in this table should be 'undeletable' CREATE table article ( id serial, content text not null,

How can I roll back my last delete command in MySQL?

陌路散爱 提交于 2019-12-18 11:38:15
问题 I accidentally deleted some huge number of rows from a table... How can I roll it back? I executed the query using PuTTY. I'll be grateful if any of you can guide me safely out of this... 回答1: If you didn't commit the transaction yet, try rollback . If you have already committed the transaction (by commit or by exiting the command line client), you must restore the data from your last backup. 回答2: If you haven't made a backup, you are pretty much fudged. 回答3: A "rollback" only works if you

How to write a trigger to abort delete in MYSQL?

独自空忆成欢 提交于 2019-12-18 10:44:54
问题 I read this article but it seems not work for delete. I got this error when tried to create a trigger: Executing SQL script in server ERROR: Error 1363: There is no NEW row in on DELETE trigger CREATE TRIGGER DeviceCatalog_PreventDeletion BEFORE DELETE on DeviceCatalog FOR EACH ROW BEGIN DECLARE dummy INT; IF old.id = 1 or old.id =2 THEN SELECT * FROM DeviceCatalog WHERE DeviceCatalog.id=NEW.id; END IF; END; SQL script execution finished: statements: 4 succeeded, 1 failed 回答1: Try something

MySQL WHERE: how to write “!=” or “not equals”?

筅森魡賤 提交于 2019-12-18 10:33:03
问题 I need to do this DELETE FROM konta WHERE taken != '' But != doesn't exist in mysql. Anyone know how to do this? 回答1: DELETE FROM konta WHERE taken <> ''; 回答2: The != operator most certainly does exist! It is an alias for the standard <> operator. Perhaps your fields are not actually empty strings, but instead NULL ? To compare to NULL you can use IS NULL or IS NOT NULL or the null safe equals operator <=>. 回答3: You may be using old version of Mysql but surely you can use DELETE FROM konta