Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-12-2009, 06:53 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
SQL deleting

How do I delete tables/colums? =O
Reply With Quote
  #2  
Old 05-12-2009, 08:44 PM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
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
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #3  
Old 05-12-2009, 09:38 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by napo_p2p View Post
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

__________________
Reply With Quote
  #4  
Old 05-13-2009, 12:14 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by cbk1994 View Post
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.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #5  
Old 05-13-2009, 01:27 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by napo_p2p View Post
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.
__________________
Reply With Quote
  #6  
Old 05-12-2009, 08:46 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
It's a good thing to vacuum after dropping a table.

NPC Code:

DROP TABLE table_name
VACUUM

__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #7  
Old 05-13-2009, 01:16 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by xXziroXx View Post
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
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:53 AM.


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