n1ckooo Posted May 15, 2008 at 08:55 PM Report Share #185380 Posted May 15, 2008 at 08:55 PM Eu sei que existem imensos topicos a falar de chaves estrageiras e eu fiz a pesquisa mas nao escontrei nada que me pudesse ajudar... Tenho duas tabelas user e sessão , como chaves primarias estão id_user e id_sessao respectivamentes.. Para definir que o id_user na tabela sessao é uma chave estranheira como faço? Vou a tabela user e lla é que digo que o campo id_user é chave estranjeira... ou viceversa? Já agora qual é a utilidade para a utilizaçao de chaves estrangeiras no mysql? Link to comment Share on other sites More sharing options...
falk0n Posted May 15, 2008 at 09:23 PM Report Share #185395 Posted May 15, 2008 at 09:23 PM em relacao a utilidade acho que deverias ir ver as 3 formas normais ... boas programacoes Link to comment Share on other sites More sharing options...
maiden Posted May 15, 2008 at 09:27 PM Report Share #185396 Posted May 15, 2008 at 09:27 PM Boas, Para criares a chave estrangeira vais à tabela onde a mesma irá constar. Na tabela que vai conter o campo da chave primária defines-la, através do código create table xpto ( campo int not null, foreign key(campo) references tabela(campo) ); Cumps, Link to comment Share on other sites More sharing options...
Gurzi Posted May 16, 2008 at 12:33 PM Report Share #185466 Posted May 16, 2008 at 12:33 PM Para começar, tens que definir como motor o InnoDB. Se já tiveres as tabelas criadas, então vais ter que fazer qualquer coisa como isto: UPDATE TABLE ADD CONSTRAINT FOREIGN KEY(ID_CHAVE) REFERENCES tabela(ID_CHAVE); Isto é o básico, depois podes criar nomes para as FK, podes adicionar acções do género ON DELETE; ON UPDATE. bastante interesante. Link to comment Share on other sites More sharing options...
n1ckooo Posted May 16, 2008 at 06:44 PM Author Report Share #185523 Posted May 16, 2008 at 06:44 PM #1005 - Can't create table '.\052317\#sql-53c_105.frm' (errno: 150) Da este erro :S Link to comment Share on other sites More sharing options...
M6 Posted May 17, 2008 at 09:21 PM Report Share #185725 Posted May 17, 2008 at 09:21 PM Aconselho a leitura do artigo de BDs da Revista Programar 5. Creio que será uma ajuda. 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now