Agregar columna en Sqlite
#1

Hola, alguien podrнa ayudarme con esto?

Es la primera vez que intento usar sqlite, estoy editando una base para aprender a usarlo y me encontrй con el problema de no poder agregar una columna.

Quiero agregar una nueva columna en la tabla, pero no sй como hacerlo.
Por lo que leн hay que usar ALTER TABLE, lo estoy usando asн, pero no funciona.



pawn Код:
Base SQLite Script  
              ------------------
              Created by: Norrin
 creativecommons.org/licenses/by-nc-nd/4.0

public OnGameModeInit()
{
        Database = db_open("database.db");
        new string[1024];
    strcat(string, "CREATE TABLE IF NOT EXISTS Accounts(");
    strcat(string, "Nombre VARCHAR(24) COLLATE NOCASE,");
    strcat(string, "Pass VARCHAR(128),");
    strcat(string, "Edad INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "Genero INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "ALTER TABLE Accounts ADD DNI INTEGER DEFAULT 0 NOT NULL)");//Lo que intento agregar.
    return 1;
}
Reply
#2

te faltaron los " ' ' " en Accounts fijate bien ahora si te crea el campo.

strcat(string, "CREATE TABLE IF NOT EXISTS Accounts(");
strcat(string, "Nombre VARCHAR(24) COLLATE NOCASE,");
strcat(string, "Pass VARCHAR(128 ),");
strcat(string, "Edad INTEGER DEFAULT 0 NOT NULL,");
strcat(string, "Genero INTEGER DEFAULT 0 NOT NULL,");
strcat(string, "ALTER TABLE 'Accounts' ADD DNI INTEGER DEFAULT 0 NOT NULL)");


Reply
#3

El ALTER TABLE debe ir por fuera del CREATE TABLE.

strcat(string, "Genero INTEGER DEFAULT 0 NOT NULL);");
strcat(string, "ALTER TABLE 'Accounts' ADD DNI INTEGER DEFAULT 0 NOT NULL;");

Y si la tabla no esta creada, mejor colocalo en el CREATE TABLE .



strcat(string, "Genero INTEGER DEFAULT 0 NOT NULL,");
strcat(string, "DNI INTEGER DEFAULT 0 NOT NULL)");
Reply
#4

hola themasternico
Reply
#5

Quote:
Originally Posted by TheMasterNico
Посмотреть сообщение
El ALTER TABLE debe ir por fuera del CREATE TABLE.

strcat(string, "Genero INTEGER DEFAULT 0 NOT NULL);");
strcat(string, "ALTER TABLE 'Accounts' ADD DNI INTEGER DEFAULT 0 NOT NULL;");

Y si la tabla no esta creada, mejor colocalo en el CREATE TABLE .



strcat(string, "Genero INTEGER DEFAULT 0 NOT NULL,");
strcat(string, "DNI INTEGER DEFAULT 0 NOT NULL)");
Gracias me sirviу pero si pongo 2 ALTER TABLE solo lee la primera linea

pawn Код:
strcat(string, "ALTER TABLE 'Accounts' ADD DNI INTEGER DEFAULT 0 NOT NULL;"); //solo lee esta
strcat(string, "ALTER TABLE 'Accounts' ADD Celular INTEGER DEFAULT 0 NOT NULL;");//esta es como si no existiera
Reply
#6

Quote:
Originally Posted by Mamoru
Посмотреть сообщение
Gracias me sirviу pero si pongo 2 ALTER TABLE solo lee la primera linea

pawn Код:
strcat(string, "ALTER TABLE 'Accounts' ADD DNI INTEGER DEFAULT 0 NOT NULL;"); //solo lee esta
strcat(string, "ALTER TABLE 'Accounts' ADD Celular INTEGER DEFAULT 0 NOT NULL;");//esta es como si no existiera
fijate bien la coma y el cierre de la tabla
Код:
strcat(string, "ALTER TABLE 'Accounts' ADD DNI INTEGER DEFAULT 0 NOT NULL,"); //
strcat(string, "ALTER TABLE 'Accounts' ADD Celular INTEGER DEFAULT 0 NOT NULL)");//
Reply
#7

Puedes hacerla asi:

Database = db_open("database.db");

db_query(Database,"CREATE TABLE IF NOT EXIST (`Nombre` VARCHAR (24) COLLATE NOCASE, `Pass` VARCHAR(12, `Edad` INTEGER DEFAULT 0 NOT NULL, `Genero` INTEGER DEFAULT 0 NOT NULL, `DNI` INTEGER DEFAULT 0 NOT NULL)");
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)