[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
how do i search an SQL database for an Id, and if i find that
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 29
Thread images: 4
File: sql.jpg (29 KB, 300x225) Image search: [Google]
sql.jpg
29 KB, 300x225
how do i search an SQL database for an Id, and if i find that ID, delete that entire row?
>>
>>51731685
select
*
from
table
where
id
=
###

delete is left as an exercise for the reader
>>
>>51731685
DELETE FROM table_name
WHERE ID = id_value

?
>>
delete from table where id = ?
>>
DELETE FROM `table` WHERE `id`=`query`
>>
File: Wizard.jpg (2 MB, 1767x1211) Image search: [Google]
Wizard.jpg
2 MB, 1767x1211
>>51731685
WHEN
FIND
Id
LOOK
AT
MATCHEY
MATCHEY
THEN
DELETE
ROW
>>
>>51731714
>>51731708
>>51731702
String selectSQL = "select r from ReservationDrop r where r.id like :id";
try {
Query selectQuery = entityManager.createQuery(selectSQL);

would work, how would i know if a row was deleted so i can confirm the deletion?
>>
>>51731685
DROP DATABASE yourdbname
>>
You'd learn more if you did your own homework, rajeesh.
>>
>>51731745
i think netbeans doesnt allow this in default
>>
>>51731742
Check the size of the table before and after. If it has decreased by one, it is successful.
There's probably a more elegant way of doing it, but it works.
>>
YOU FORGOT THE COMMIT

-1000 points

faggots
>>
>>51731685
are you a retard? why the fuck even make a thread when bing could've got you the answer in seconds?
>>
>>51731783
He wanted the 4chan experience
>>
>>51731755
there was no mention of ide or even sql dialect. it would work on mssql and everyone knows that this is the only logical choice for actual business databases.
>>
>>51731742
Add
OUTPUT deleted.*
somewhere in there
>>
ANSI SQL faglords why would you use vendor specific code to delete a row
>>
>>51731822
what should i use?
>>
>>51731685

function DeleteRowFromDatabaseThatMatchesID(int Id)
{
DatabaseConnector conn(DB_ID, DB_USER, DB_PASSWORD);

if (!conn.connect())
return false;

DatabaseSelector select(conn);
select.find("ID", "EQU", Id);
if (!select.found())
return false;

DatabaseDeleter delete(selector);
if (!delete.delete())
return false;

return true;
}


Easy peasy.
>>
>>51732117
>let's do two operations when one will suffice
confirmed for not knowing the first thing about databases
>>
Just delete it. Why the hell do you need to search it first?
>>
>>51731790
>He wanted the 4chan experience
moot should of branded this to make more shekels
>inb4 should of
>>
>>51731685
anon, we know this is your homework... please try to do it by yourself or else you will never learn about SQL
>>
>>51731685
delete from table_name where ID = (select id from table_name where Id = ?)
>>
File: 1379677716726.jpg (20 KB, 465x306) Image search: [Google]
1379677716726.jpg
20 KB, 465x306
>>51736587
>select id where id =
>>
>>51736587
>>51737330
see
>>51732810
>>
TRUNCATE TABLE dbo.table
>>
Speaking of which, why does beautifying code in mysql make it look so much shittier? No I don't want a simple command to take up 6 lines.
>>
File: 1427363418786.webm (2 MB, 804x434) Image search: [Google]
1427363418786.webm
2 MB, 804x434
>>51737330
>he doesn't know what sub-queries are
Thread replies: 29
Thread images: 4

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.