Deleting a whole column in SQLite
#1

Title says it all, how could i delete a column from a TABLE?

Something i wrote which wont work!
pawn Code:
stock DeleteGang(gangid)
{
    new Query[256], DBResult:Result;
    format(Query, sizeof(Query), "DELETE FROM `GANGS` WHERE `GANGID` = '%d'", gangid);
    Result = db_query(Database, Query);
    return db_free_result(Result);
}
Reply
#2

ALTER TABLE 'table_name' DROP 'column_name'
Reply
#3

Damn, IDK where to use that but i just want to make something that will search for a certain GANGID and delete the place where the gang id is but the current code i have wont work basicly, if you're right do you mind posting an example to what i should do to do this
Reply
#4

Do you understand the difference between a column and a row?
Reply
#5

Well, in mysql no, in SQL not really, i just started using sql a couple of days ago

and what i ment by COLUMN is the complete line of the gang
`GANGNAME`, `GANGID`, `GANGLEADER`

for example
Reply
#6

columns = |
rows = __

If you use the query you posted in your first post, that will delete the row which has %d as gang ID.
Or tell us what exactly you want to do, then it might be easier to explain ..
Reply
#7

Well i want to delete the whole row with the gangid = '%d'

Damn lol i got confused with columns and rows the opposite way :/

Inside the Table (GANGS) this is the format given when each gang is created:

Code:
GANGNAME:        GANGID:        GANGLEADER:
test                  1                  [Nova]Lorenc
I thought about the same way you did before about the deleting thing, thats why i posted here to gather more information and how to achieve this.
Reply
#8

Supposing GANGID is an integer, try this instead;
DELETE FROM `GANGS` WHERE `GANGID` = %d

The query is definitely OK and should delete the row.
You also don't need to use free_result when deleting a row.
Reply
#9

Alright, thanks.

pawn Code:
stock DeleteGang(gangid)
{
    new Query[256];
    format(Query, sizeof(Query), "DELETE FROM `GANGS` WHERE `GANGID` = %d", gangid);
    db_query(Database, Query);
}
Thats how my code looks like now, not sure if it works or not.
Reply
#10

Test it and see! Although you may want to loop through all connected players, see if their gang == gangid, and if so set their gang to 0.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)