Alterando muitas Foreign Keys [Resolvido]  XML
Índice dos Fóruns » Assuntos gerais (Off-topic)
Autor Mensagem
felipe_thrash
JavaGuru
[Avatar]

Membro desde: 02/07/2007 13:36:02
Mensagens: 240
Localização: Brasil
Offline

Boa tarde galera,

... estou tentando bolar um script, onde irei alterar muitas FK's de um banco... só por questoes de gramática...

o problema é que são muitas é não é possivel ir na mão...

visualizem o ponto inicial:


teria que fazer isso para muitas FK's...

alguem pode me ajudar em bolar alguma coisa ?

valew

This message was edited 1 time. Last update was at 16/02/2008 11:04:50


Need money for a f*%#ing beer!
felipe_thrash
JavaGuru
[Avatar]

Membro desde: 02/07/2007 13:36:02
Mensagens: 240
Localização: Brasil
Offline

e como listar as PK's de tabelas num select ??? alguem sabe....

estou dando um select nas constraints e fazer a gramatica virar magica.... mas nao sei como listar só PK's de tabelas...

alguem sabe ???

Need money for a f*%#ing beer!
boaglio
Moderador
[Avatar]

Membro desde: 09/09/2002 21:23:39
Mensagens: 1865
Localização: Sampa City
Offline


Dependendo da alteração q vc precisa fazer, tem q ser manual mesmo.

No Oracle, para listar as PKs de suas tabelas , o SQL é esse:



Quer saber as colunas envolvidas e outros tipos de constraints?

Estude o dicionário de dados!


 

Tem dúvidas de Java? Poste no fórum! Não respondo dúvidas de Java via MP!
[WWW]
felipe_thrash
JavaGuru
[Avatar]

Membro desde: 02/07/2007 13:36:02
Mensagens: 240
Localização: Brasil
Offline

problema... quando faço o filtro:


mato minha relação de FK's....
estou fazendo para as FK's... esse é o pau!


preciso listar aki a PK da minha table !!!

será q tem jeito !?

Need money for a f*%#ing beer!
gustavo_apsilva
JavaBaby

Membro desde: 25/06/2007 20:33:10
Mensagens: 95
Localização: Matão-SP
Offline

Bom, vc poderia ter uma "ajuda" com JDBC
SuaConnection.getMetaData().getExportedKeys(parametros)
devolve algumas informações...

ResultSet java.sql.DatabaseMetaData.getExportedKeys(String catalog, String schema, String table)
Retrieves a description of the foreign key columns that reference the given table's primary key columns (the foreign keys exported by a table). They are ordered by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, and KEY_SEQ.

Each foreign key column description has the following columns:

PKTABLE_CAT String => primary key table catalog (may be null)
PKTABLE_SCHEM String => primary key table schema (may be null)
PKTABLE_NAME String => primary key table name
PKCOLUMN_NAME String => primary key column name
FKTABLE_CAT String => foreign key table catalog (may be null) being exported (may be null)
FKTABLE_SCHEM String => foreign key table schema (may be null) being exported (may be null)
FKTABLE_NAME String => foreign key table name being exported
FKCOLUMN_NAME String => foreign key column name being exported
KEY_SEQ short => sequence number within foreign key
UPDATE_RULE short => What happens to foreign key when primary is updated:
importedNoAction - do not allow update of primary key if it has been imported
importedKeyCascade - change imported key to agree with primary key update
importedKeySetNull - change imported key to NULL if its primary key has been updated
importedKeySetDefault - change imported key to default values if its primary key has been updated
importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility)
DELETE_RULE short => What happens to the foreign key when primary is deleted.
importedKeyNoAction - do not allow delete of primary key if it has been imported
importedKeyCascade - delete rows that import a deleted key
importedKeySetNull - change imported key to NULL if its primary key has been deleted
importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility)
importedKeySetDefault - change imported key to default if its primary key has been deleted
FK_NAME String => foreign key name (may be null)
PK_NAME String => primary key name (may be null)
DEFERRABILITY short => can the evaluation of foreign key constraints be deferred until commit
importedKeyInitiallyDeferred - see SQL92 for definition
importedKeyInitiallyImmediate - see SQL92 for definition
importedKeyNotDeferrable - see SQL92 for definition
Parameters:
catalog a catalog name; must match the catalog name as it is stored in this database; "" retrieves those without a catalog; null means that the catalog name should not be used to narrow the search
schema a schema name; must match the schema name as it is stored in the database; "" retrieves those without a schema; null means that the schema name should not be used to narrow the search
table a table name; must match the table name as it is stored in this database
Returns:
a ResultSet object in which each row is a foreign key column description
Throws:
SQLException if a database access error occurs
See Also:
getImportedKeys


pelo metadata da conecction vc consegue uma lista das tabelas tb, então nao sei se teria como vc "automatizar" isso...

Se nao for isso que procura, desculpe..
oyama
Virtual Machine Man

Membro desde: 19/04/2005 10:11:09
Mensagens: 572
Offline


boaglio wrote:Estude o dicionário de dados!

Estude também um pouco de SQL!!!
felipe_thrash
JavaGuru
[Avatar]

Membro desde: 02/07/2007 13:36:02
Mensagens: 240
Localização: Brasil
Offline

pessoal...

os scripts levam ao mesmo lugar, preciso da PK na mesma linha da minha FK ... mas bem.. acho q estou me confundindo tb.. acho q nao é por aki...

volto ao ponto inicial,


com certeza nao é simples...
é um script mesmo, para alterar o nome de toda FK q nao esteja na ordem gramatical do banco...
e essa FK depende do nome da PK da tabela mãe e da PK referenciada.... igual ao código....



alguem pode me mostrar outro caminho ???


Need money for a f*%#ing beer!
oyama
Virtual Machine Man

Membro desde: 19/04/2005 10:11:09
Mensagens: 572
Offline

Era só dar uma garibada no meu SELECT (acho que SQL/dicionário de dados do Oracle não é o seu forte)!!!


O "alter table drop FK" eu deixo como tarefa de casa...
felipe_thrash
JavaGuru
[Avatar]

Membro desde: 02/07/2007 13:36:02
Mensagens: 240
Localização: Brasil
Offline

oyama wrote:
O "alter table drop FK" eu deixo como tarefa de casa...


é isso aí... e tarefa feita !! heheh




Muito obrigado a todos que ajudaram!

é q ainda sou basicao no SQL heheh
valeu!




Need money for a f*%#ing beer!
 
Índice dos Fóruns » Assuntos gerais (Off-topic)
Ir para:   
Powered by JForum 2.1.8 © JForum Team