Posts: 54
Threads: 15
Joined: Jun 2008
Reputation:
0
I'm using SAMP SQL for users system and i want to delete some column when the table is already exist with a command only.
I'm using this:
ALTER TABLE x DROP COLUMN y
but it doesn't work?
It's work for you?, or you have any solution for me?
Posts: 54
Threads: 15
Joined: Jun 2008
Reputation:
0
You mean I need to do that?:
1)Rename Y to Z(Table name)
2)Read the table with SELECT
3)Make Table with the name Y
4)add all COLUMNS i need.
5)Insert, but HOW?
Posts: 79
Threads: 5
Joined: May 2006
Reputation:
0
Lets say you had the following table
[code=SQLite]
CREATE TABLE IF NOT EXISTS `users` ( `name` TEXT NOT NULL PRIMARY KEY COLLATE NOCASE , `money` INTEGER NOT NULL DEFAULT 0 , `unusedcolumn` );
INSERT INTO `users` ( `name` ) VALUES ( 'player1' );
INSERT INTO `users` ( `name` ) VALUES ( 'player2' );
INSERT INTO `users` ( `name` ) VALUES ( 'player3' );
[/code]
To remove the `unusedcolumn` column, you would use these queries
[code=SQLite]
ALTER TABLE `users` RENAME TO `old_users`;
CREATE TABLE `users` ( `name` TEXT NOT NULL PRIMARY KEY COLLATE NOCASE , `money` INTEGER NOT NULL DEFAULT 0 );
INSERT INTO `users` SELECT `name` , `money` FROM `old_users`;
DROP TABLE `old_users`;
[/code]
Posts: 79
Threads: 5
Joined: May 2006
Reputation:
0
Just select all the columns you want.
[code=SQLite]
INSERT INTO `table` SELECT `col1` , `col2`, `col3` , `col4` , `col5` , `col6` FROM `old_table`
[/code]
etc...