Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   SQL deleting (https://forums.graalonline.com/forums/showthread.php?t=85549)

[email protected] 05-12-2009 06:53 PM

SQL deleting
 
How do I delete tables/colums? =O

napo_p2p 05-12-2009 08:44 PM

For tables, you can just do:
NPC Code:
DROP TABLE table_name



Columns are a bit more tricky, because it turns out that SQLite has limited support for altering columns... you can check out: http://www.sqlite.org/faq.html#q11

xXziroXx 05-12-2009 08:46 PM

It's a good thing to vacuum after dropping a table.

NPC Code:

DROP TABLE table_name
VACUUM


cbk1994 05-12-2009 09:38 PM

Quote:

Originally Posted by napo_p2p (Post 1491123)
For tables, you can just do:
NPC Code:
DROP TABLE table_name



Columns are a bit more tricky, because it turns out that SQLite has limited support for altering columns... you can check out: http://www.sqlite.org/faq.html#q11

What?

NPC Code:

DELETE FROM table_name WHERE var = 'val'



e.g.

NPC Code:

DELETE FROM jailed WHERE account = 'cbk1994'



EDIT: Sorry, I misread; I think that Andrew was talking about rows anyway, though.

And, for columns you can use

NPC Code:

ALTER TABLE table_name
DROP COLUMN column


napo_p2p 05-13-2009 12:14 AM

Quote:

Originally Posted by cbk1994 (Post 1491146)
And, for columns you can use

NPC Code:

ALTER TABLE table_name
DROP COLUMN column


For MySQL, yes. With SQLite (default database for Graal servers), you can only rename or add columns when altering tables. Dropping columns is not directly supported.

Inverness 05-13-2009 01:16 AM

Quote:

Originally Posted by xXziroXx (Post 1491126)
It's a good thing to vacuum after dropping a table.

NPC Code:

DROP TABLE table_name
VACUUM


Actually, no it isn't, considering HD space is not vital unless Stefan says so. SQLite uses that empty space for future data, it can write to the file without having to resize it.

In SQLite if you want to drop a column you should create a backup table. If you want to drop column b in a table named spelling that has columns a, b, c, you would do:

BEGIN
CREATE TABLE spelling_bak AS SELECT a, c FROM spelling
DROP TABLE spelling
CREATE TABLE spelling AS SELECT * FROM spelling_bak
COMMIT

cbk1994 05-13-2009 01:27 AM

Quote:

Originally Posted by napo_p2p (Post 1491171)
For MySQL, yes. With SQLite (default database for Graal servers), you can only rename or add columns when altering tables. Dropping columns is not directly supported.

Oh, thanks for correcting me :)

I've never actually done it myself.


All times are GMT +2. The time now is 02:33 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.