第一次建立数据库,有很多问题,求指教
use movie
create table actors
(
AID numeric(4,0) primary key,
name varchar(8),
);
create table movies
(
MID numeric(4,0) primary key,
title varchar(15),
);
create table actor_role
(
MID numeric(4,0),
AID numeric(4,0),
rolename varchar(15),
foreign key (MID) references movies,
foreign key (AID) references actors,
primary key (MID,AID),
); //这是表格的建立
use movie
insert into movies values (0001,'breaveheart');
insert into movies values (0002,'whitehouse');
insert into movies values (0003,'batman');
insert into movies values (0004,'spiderman');
insert into movies values (0005,'superman');
insert into actors values (1111,'brucelee');
insert into actors values (2222,'frank');
insert into actors values (3333,'jimmy');
insert into actors values (4444,'sky');
insert into actors values (5555,'enda');
insert into actor_role values (0001,3333,'shaw');
insert into actor_role values (0001,5555,'wayen');
insert into actor_role values (0002,2222,'cale');
insert into actor_role values (0002,1111,'lee');
insert into actor_role values (0003,5555,'park');
insert into actor_role values (0004,1111,'paul');
insert into actor_role values (0005,2222,'bayen');
//这是数据的录入
但是出现了很多错误:
Violation of PRIMARY KEY constraint 'PK__movies__C797348A03317E3D'. Cannot insert duplicate key in object 'dbo.movies'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 4
Violation of PRIMARY KEY constraint 'PK__movies__C797348A03317E3D'. Cannot insert duplicate key in object 'dbo.movies'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 5
Violation of PRIMARY KEY constraint 'PK__movies__C797348A03317E3D'. Cannot insert duplicate key in object 'dbo.movies'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 6
Violation of PRIMARY KEY constraint 'PK__movies__C797348A03317E3D'. Cannot insert duplicate key in object 'dbo.movies'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 7
Violation of PRIMARY KEY constraint 'PK__movies__C797348A03317E3D'. Cannot insert duplicate key in object 'dbo.movies'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 9
Violation of PRIMARY KEY constraint 'PK__actors__C69007C87F60ED59'. Cannot insert duplicate key in object 'dbo.actors'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 10
Violation of PRIMARY KEY constraint 'PK__actors__C69007C87F60ED59'. Cannot insert duplicate key in object 'dbo.actors'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 11
Violation of PRIMARY KEY constraint 'PK__actors__C69007C87F60ED59'. Cannot insert duplicate key in object 'dbo.actors'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 12
Violation of PRIMARY KEY constraint 'PK__actors__C69007C87F60ED59'. Cannot insert duplicate key in object 'dbo.actors'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 13
Violation of PRIMARY KEY constraint 'PK__actors__C69007C87F60ED59'. Cannot insert duplicate key in object 'dbo.actors'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 15
Violation of PRIMARY KEY constraint 'PK__actor_ro__5BFE34F607020F21'. Cannot insert duplicate key in object 'dbo.actor_role'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 16
Violation of PRIMARY KEY constraint 'PK__actor_ro__5BFE34F607020F21'. Cannot insert duplicate key in object 'dbo.actor_role'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 17
Violation of PRIMARY KEY constraint 'PK__actor_ro__5BFE34F607020F21'. Cannot insert duplicate key in object 'dbo.actor_role'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 18
Violation of PRIMARY KEY constraint 'PK__actor_ro__5BFE34F607020F21'. Cannot insert duplicate key in object 'dbo.actor_role'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 19
Violation of PRIMARY KEY constraint 'PK__actor_ro__5BFE34F607020F21'. Cannot insert duplicate key in object 'dbo.actor_role'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 20
Violation of PRIMARY KEY constraint 'PK__actor_ro__5BFE34F607020F21'. Cannot insert duplicate key in object 'dbo.actor_role'.
The statement has been terminated.
Msg 2627, Level 14, State 1, Line 21
Violation of PRIMARY KEY constraint 'PK__actor_ro__5BFE34F607020F21'. Cannot insert duplicate key in object 'dbo.actor_role'.
The statement has been terminated.
到底是哪里出了错误,求指正。
[解决办法]
create table actors
(
AID numeric(4,0) primary key,
name varchar(8),
);
create table movies
(
MID numeric(4,0) primary key,
title varchar(15),
);
create table actor_role
(
MID numeric(4,0),
AID numeric(4,0),
rolename varchar(15),
foreign key (MID) references movies,
foreign key (AID) references actors,
primary key (MID,AID),
);
insert into movies values (0001,'breaveheart');
insert into movies values (0002,'whitehouse');
insert into movies values (0003,'batman');
insert into movies values (0004,'spiderman');
insert into movies values (0005,'superman');
insert into actors values (1111,'brucelee');
insert into actors values (2222,'frank');
insert into actors values (3333,'jimmy');
insert into actors values (4444,'sky');
insert into actors values (5555,'enda');
insert into actor_role values (0001,3333,'shaw');
insert into actor_role values (0001,5555,'wayen');
insert into actor_role values (0002,2222,'cale');
insert into actor_role values (0002,1111,'lee');
insert into actor_role values (0003,5555,'park');
insert into actor_role values (0004,1111,'paul');
insert into actor_role values (0005,2222,'bayen');
--create database movie
--go
use movie
go
create table actors
(
AID numeric(4,0) primary key,
name varchar(8),
);
create table movies
(
MID numeric(4,0) primary key,
title varchar(15),
);
create table actor_role
(
MID numeric(4,0),
AID numeric(4,0),
rolename varchar(15),
foreign key (MID) references movies,
foreign key (AID) references actors,
primary key (MID,AID),
); --注意不能用//,这个不是注释,这是表格的建立
use movie
go
insert into movies values (0001,'breaveheart');
insert into movies values (0002,'whitehouse');
insert into movies values (0003,'batman');
insert into movies values (0004,'spiderman');
insert into movies values (0005,'superman');
insert into actors values (1111,'brucelee');
insert into actors values (2222,'frank');
insert into actors values (3333,'jimmy');
insert into actors values (4444,'sky');
insert into actors values (5555,'enda');
insert into actor_role values (0001,3333,'shaw');
insert into actor_role values (0001,5555,'wayen');
insert into actor_role values (0002,2222,'cale');
insert into actor_role values (0002,1111,'lee');
insert into actor_role values (0003,5555,'park');
insert into actor_role values (0004,1111,'paul');
insert into actor_role values (0005,2222,'bayen');
use master
go
drop database movie
go
create database movie
go
use movie
go
create table actors
(
AID numeric(4,0) primary key,
name varchar(8),
);
create table movies
(
MID numeric(4,0) primary key,
title varchar(15),
);
create table actor_role
(
MID numeric(4,0),
AID numeric(4,0),
rolename varchar(15),
foreign key (MID) references movies,
foreign key (AID) references actors,
primary key (MID,AID),
); --注意不能用//,这个不是注释,这是表格的建立
use movie
go
insert into movies values (0001,'breaveheart');
insert into movies values (0002,'whitehouse');
insert into movies values (0003,'batman');
insert into movies values (0004,'spiderman');
insert into movies values (0005,'superman');
insert into actors values (1111,'brucelee');
insert into actors values (2222,'frank');
insert into actors values (3333,'jimmy');
insert into actors values (4444,'sky');
insert into actors values (5555,'enda');
insert into actor_role values (0001,3333,'shaw');
insert into actor_role values (0001,5555,'wayen');
insert into actor_role values (0002,2222,'cale');
insert into actor_role values (0002,1111,'lee');
insert into actor_role values (0003,5555,'park');
insert into actor_role values (0004,1111,'paul');
insert into actor_role values (0005,2222,'bayen');