Usuário com melhor resposta
criação de uma base de dados para uma federação

Pergunta
-
criei essa Base de Dados só quando tento executar ela da-me os seguintes erros, o que eu quero saber é como elimina-lo porque por causa dele não consigo relacionar as minhas tabelas, mas consigo criar as chaves primaria só não consigo relaciona-las e como faço para eliminar esses erros e permitir que a minha tabela tenha um bom funcionamento, a linguagem é SQL SERVER 2005.
Obrigado
Msg 1801, Level 16, State 3, Line 1
Database 'db_Girabola' already exists.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'jornadas'.
Msg 2714, Level 16, State 6, Line 1
There is already an object named 'tb_equipa' in the database.
Msg 2714, Level 16, State 6, Line 1
There is already an object named 'tb_vitorias' in the database.
Msg 2714, Level 16, State 6, Line 1
There is already an object named 'tb_derrotas' in the database.
Msg 2714, Level 16, State 6, Line 1
There is already an object named 'tb_golos_marcados' in the database.
Msg 2714, Level 16, State 6, Line 1
There is already an object named 'tb_golos_sofridos' in the database.
Msg 2714, Level 16, State 6, Line 1
There is already an object named 'tb_telefone_equipa' in the database.
Msg 2714, Level 16, State 6, Line 1
There is already an object named 'tb_jogador' in the database.
Msg 2714, Level 16, State 6, Line 1
There is already an object named 'tb_nacionalidade_jogador' in the database.
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'add'.
Msg 1779, Level 16, State 0, Line 2
Table 'tb_equipa' already has a primary key defined on it.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
Msg 1779, Level 16, State 0, Line 2
Table 'tb_vitorias' already has a primary key defined on it.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
Msg 1779, Level 16, State 0, Line 2
Table 'tb_derrotas' already has a primary key defined on it.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
Msg 1779, Level 16, State 0, Line 2
Table 'tb_golos_marcados' already has a primary key defined on it.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
Msg 1779, Level 16, State 0, Line 2
Table 'tb_golos_sofridos' already has a primary key defined on it.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
Msg 1779, Level 16, State 0, Line 2
Table 'tb_jogador' already has a primary key defined on it.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
Msg 1779, Level 16, State 0, Line 2
Table 'tb_nacionalidade_jogador' already has a primary key defined on it.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'add'.
Msg 1769, Level 16, State 1, Line 2
Foreign key 'fk_tb_telefone_equipa_tb_equipa' references invalid column 'cod_equipa' in referencing table 'tb_telefone_equipa'.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
Msg 1769, Level 16, State 1, Line 2
Foreign key 'fk_tb_equipa_tb_jogador' references invalid column 'cod_equipa' in referencing table 'tb_jogador'.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'jornadas'.
Msg 1769, Level 16, State 1, Line 1
Foreign key 'fk_tb_vitorias_tb_equipa' references invalid column 'cod_equipa' in referencing table 'tb_vitorias'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
Msg 1769, Level 16, State 1, Line 1
Foreign key 'fk_tb_golos_marcados_tb_equipa' references invalid column 'cod_equipa' in referencing table 'tb_golos_marcados'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
Msg 1769, Level 16, State 1, Line 1
Foreign key 'fk_tb_equipa_tb_golos_sofridos' references invalid column 'cod_equipa' in referencing table 'tb_golos_sofridos'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
Msg 1769, Level 16, State 1, Line 1
Foreign key 'fk_tb_derrotas_tb_equipa' references invalid column 'cod_equipa' in referencing table 'tb_derrotas'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
---------------------------------------------------------------------------------------------------------
create database db_Girabola
go
use db_Girabola
go
create table tb_ jornadas
(
Id_ jornadas int not null
,jornadas int not null
,jogos_adiados int
,jogos_realizados int
)
go
create table tb_equipa
(
cod_equipa int not null
,equipa varchar(30)not null
, pontos int not null
,empates int
)
go
create table tb_vitorias
(
Id_vitorias int not null
,vitorias_casa int
,vitorias_fora int
)
go
create table tb_derrotas
(
Id_derrotas int not null
,derrotas_casa int
,derrotas_fora int
)
go
create table tb_golos_marcados
(
Id_golos_marcados int not null
,golos_marcados_casa int
,golos_marcados_fora int
)
go
create table tb_golos_sofridos
(
Id_golos_sofridos int not null
,golos_sofridos_casa int
,golos_sofridos_fora int
)
go
create table tb_telefone_equipa
(
Id_telefone_equipa int not null
,telefone_equipa varchar(13)not null
)
go
create table tb_jogador
(
BI_jogador int not null
,N_inscricao int not null
,jogador varchar(50)not null
)
go
create table tb_nacionalidade_jogador
(
Id_nacionalidade int not null
,nacionalidade varchar(20)not null
,lingua varchar(15)not null
)
go
alter table tb_ jornadas add constraint fk_tb_ jornadas
primary key(Id_ jornadas)
go
alter table tb_equipa add constraint fk_tb_equipa
primary key(cod_equipa)
go
alter table tb_vitorias add constraint pk_tb_vitorias
primary key(Id_vitorias)
go
alter table tb_derrotas add constraint fk_tb_derrotas
primary key(Id_derrotas)
go
alter table tb_golos_marcados add constraint fk_tb_golos_marcados
primary key(Id_golos_marcados)
go
alter table tb_golos_sofridos add constraint fk_tb_golos_sofridos
primary key(Id_golos_sofridos)
alter table tb_telefone_equipa add constraint fk_tb_telefone_equipa
primary key(Id_telefone_equipa)
go
alter table tb_jogador add constraint fk_tb_jogador
primary key(BI_jogador)
go
alter table tb_nacionalidade_jogador add constraint pk_tb_nacionalidade_jogador
primary key(Id_nacionalidade)
go
alter table tb_ jornadas add constraint fk_tb_ jornadas_tb_equipa
foreign key(cod_equipa)references tb_equipa(cod_equipa)
go
alter table tb_telefone_equipa add constraint fk_tb_telefone_equipa_tb_equipa
foreign key(cod_equipa)references tb_equipa(cod_equipa)
go
alter table tb_jogador add constraint fk_tb_equipa_tb_jogador
foreign key(cod_equipa)references tb_equipa(cod_equipa)
go
alter table tb_jogador add constraint fk_tb_jogador_tb_nacionalidade
foreign key(Id_ jornadas)references tb_jogador(Id_ jornadas)
go
alter table tb_vitorias add constraint fk_tb_vitorias_tb_equipa
foreign key(cod_equipa)references tb_equipa(cod_equipa)
go
alter table tb_golos_marcados add constraint fk_tb_golos_marcados_tb_equipa
foreign key(cod_equipa)references tb_equipa(cod_equipa)
go
alter table tb_golos_sofridos add constraint fk_tb_equipa_tb_golos_sofridos
foreign key(cod_equipa)references tb_equipa(cod_equipa)
go
alter table tb_derrotas add constraint fk_tb_derrotas_tb_equipa
foreign key(cod_equipa)references tb_equipa(cod_equipa)
go
Respostas
-
Anacleto, bom dia,
Se a base de dados e tabelas já existem você não deve utilizar o comando CREATE, mas sim o ALTER.
Caso não tenha algum problema eliminar a base existente para que você a crie novamente, execute o comando abaixo para depois executar seu script de criação.
USE master
DROP DATABASE db_Girabola
GOAtt,
Rafael Godoi Sabadin
http://www.linkedin.com/in/rafaelgodoisabadin
Classifique as respostas. O seu feedback é essencial.- Sugerido como Resposta Adriano Ap Nascimento quinta-feira, 26 de abril de 2012 12:55
- Marcado como Resposta Heloisa Pires quarta-feira, 6 de junho de 2012 14:15