Visualizzazione dei risultati da 1 a 9 su 9
  1. #1

    Modificare tabelle Java DB

    salve a tutti,
    ieri ho provato in tutti i modi a modificare un db che ho fatto con java db (apache derby)
    all'interno di netbeans e non ci sono riuscito...
    all'interno intendo nella sezione service-> database -> execute command
    mi dà l'errore ogni volta che scrivo un drop.

    in più vorrei un indice che si autoincrementa, ma quando inserisco il codice
    codice:
    insert into pi values ('Duomo', 'via duomo');
    mi dice che manca la colonna id, non c'è modo di automatizzare l'incremento dell'id?
    la table è fatta così:
    codice:
    CREATE table pi (
        ID          INTEGER NOT NULL 
                    PRIMARY KEY GENERATED ALWAYS AS IDENTITY 
                    (START WITH 1, INCREMENT BY 1),
        NOME    VARCHAR(30), 
        INDIRIZZO   VARCHAR(30)
          )
    C'è qualcosa che mi sfugge? GRAZIE

  2. #2
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Non ho mai usato Apache Derby, ma dalla documentazione online, leggo:

    GENERATED ALWAYS
    An identity column that is GENERATED ALWAYS will increment the default value on every insertion and will store the incremented value into the column. Unlike other defaults, you cannot insert a value directly into or update an identity column that is GENERATED ALWAYS. Instead, either specify the DEFAULT keyword when inserting into the identity column, or leave the identity column out of the insertion column list altogether. For example:

    create table greetings (i int generated always as identity, ch char(50));
    insert into greetings values (DEFAULT, 'hello');
    insert into greetings(ch) values ('bonjour');
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  3. #3
    fantastico grazie con il DEFAULT funziona benissimo.

    Per quanto riguarda l'altro problema, pensi sia colpa di derby?
    Hai mai provato a cancellare una colonna da una table?

    ho provato qualunque combinazione ma, per cancellare una colonna è veramente arduo.
    Cliccando con il tasto destro sulla colonna "delete" è in grigetto,
    e scrivendo
    codice:
    ALTER TABLE pi DROP COLUMN carro;
    viene sempre generato l'errore

    codice:
    Error code -1, SQL state 42X01: Errore di sintassi: Encountered "drop" at line 1, column 16.
    fa così sia con la parola DROP che con SET (ho provato a fare set unused)
    Non so sembra che mezza sintassi sql non venga riconosciuta, è un limite di netbeans o non dovrebbe farlo?

  4. #4
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,481
    Su internet ho trovato una risposta al tuo quesito ...

    "You are correct, Derby does not support dropping columns
    in the ALTER TABLE statement.

    The Derby Reference Manual for the ALTER TABLE statement lists PRIMARY KEYS, FOREIGN KEYS and CONSTRAINTS as the only supported objects to drop."

    ... non so se ti possa servire ...
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  5. #5
    davvero?? Non è possibile, perchè mai dovrebbero togliere funzionalità ad alter table?
    Ma se è così veramente, mi conviene cambiare dbms?

    Qui c'è scritto che è supportato alter table drop column (o ho letto male io?)
    http://publib.boulder.ibm.com/infoce...ql9241891.htmlhttp://publib.boulder.ibm.com/infoce...ql9241891.html

  6. #6
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Sempre dalla documentazione online di Apache Derby (ma sono solo io che la leggo??):

    Dropping columns
    ALTER TABLE DROP COLUMN allows you to drop a column from a table.
    The keyword COLUMN is optional.
    The keywords CASCADE and RESTRICT are also optional. If you specify neither CASCADE nor RESTRICT, the default is CASCADE.
    If you specify RESTRICT, then the column drop will be rejected if it would cause a dependent schema object to become invalid.
    If you specify CASCADE, then the column drop should additionally drop other schema objects which have become invalid.
    The schema objects which can cause a DROP COLUMN RESTRICT to be rejected include: views, triggers, primary key constraints, foreign key constraints, unique key constraints, check constraints, and column privileges. If one of these types of objects depends on the column being dropped, DROP COLUMN RESTRICT will reject the statement.
    You may not drop the last (only) column in a table.
    DROP COLUMN is not allowed if sqlAuthorization is true (see DERBY-1909).
    CASCADE/RESTRICT doesn't consider whether the column being dropped is used in any indexes. When a column is dropped, it is removed from any indexes which contain it. If that column was the only column in the index, the entire index is dropped.
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  7. #7
    scusa,
    ma in effetti ho letto diverse guide online di javaDB, e tutte mi dicevano di scrivere alter table drop ecc.

    comunque ho riletto bene la pagina che ho linkato prima e c'è scritto derby NO

    Table 12. Support for SQL-92 Features: Basic schema manipulation
    Feature Source Derby

    ALTER TABLE DROP COLUMN SQL92T no

    quindi devo rassegnarmi...
    però andbin sulla documentazione che mi hai cortesemente allegato c'è scritto
    DROP COLUMN is not allowed if sqlAuthorization is true (see DERBY-1909).

    potresti darm iqualche dritta in più? Per esempio come è possibile cambiare quella sqlAuthorization?
    questa è l'ultima domanda poi mi fermo

  8. #8
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Originariamente inviato da wilma5941
    Per esempio come è possibile cambiare quella sqlAuthorization?
    Sempre dalla documentazione online:

    Setting the SQL standard authorization mode
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  9. #9
    Originariamente inviato da andbin
    Sempre dalla documentazione online:

    Setting the SQL standard authorization mode
    Cavoli ho provato tutto ma ancora mi dice
    codice:
    Error code -1, SQL state 42X01: Errore di sintassi: Encountered "drop" at line 1, column 16.
    ho eseguito il comando

    codice:
    CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(
        'derby.database.sqlAuthorization',
        'true')
    e anche

    codice:
    CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(
        'derby.database.fullAccessUsers', 'marco,erik')
    ma niente... per caso c'è un altro metodo per modificare al volo il database?
    ad esempio con hsqldb mi ricordo che c'era un file con tutte le info del database, e bastava aprirlo come un txt e cancellare il contenuto, qualcosa del genere in derby non c'è?
    grazie ancora

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.