2014-04-14 7 views
-1

안녕하세요.이 표가 거의 다되었지만 해결할 수없는 문제가 발생했습니다.MySql 오류 코드 1136 열 개수 값이 일치하지 않습니다. 행 번호가 1입니다.

나는 계속 인 Column doesn't match value count for row 1 인 오류 1136을 계속 가지므로 데이터 유형 문제이지만 그것을 이해할 수 없습니다.

Create Schema Visit; 


create table roomtableS(
RoomID char (2)  not null, 
RoomNum char (2) not null, 
Charge integer not null, 
CONSTRAINT RoomTable_PK Primary Key(RoomID)); 


Insert into roomtableS values 
('01','1A',125.00), 
('02','1A',150.00), 
('03','1A',100.00), 
('04','1A',200.00), 
('05','2B',150.00), 
('06','2B',125.00), 
('07','3C',200.00), 
('08','3C',125.00), 
('09','3C',100.00); 





SELECT * FROM ROOMTABLES; 


create table PATIENT(
PatientID char(5) not null, 
PatientName Char(25) not null, 
PatientEmail  Char(30) null, 
PatientPhoneNumber Char(10) null, 
PatientAddress Char(100) null, 
constraint PATIENT_PK Primary key(PatientID)); 

insert PATIENT values 
('P1', 'Bruce Willis', '[email protected]', '2022223333', '1111 Cosmic dr'), 
('P2', 'Demi Moore', '[email protected]', '2021113333', '1112 Cosmic dr'), 
('P3', 'Andre Agassi', '[email protected]', '2023333333', '1113 Cosmic dr'), 
('P4', 'Jet Lee', '[email protected]', '2023334444', '1114 Chinatown ct'), 
('P5', 'Jim Carey', '[email protected]', '2023335555', '1115 United dr'), 
('P6', 'Bruce Lee', '[email protected]', '2023336666', '1115 Chinatown ct'); 

select* From PATIENT; 




Create table SERVICETable(
ServiceID  Char (5) not null, 
ServiceTreatment Char(25) not null, 
ServiceCost  numeric not null, 
constraint SERVICE_PK Primary Key(ServiceID)); 

insert SERVICETable values 
('S1','Sore throat', 10.00), 
('S2', 'Fever', 15.00), 
('S3', 'Headache', 10.00), 
('S4', 'Blood pressusre', 20.00), 
('S5', 'Yearly checkup', 30.00), 
('S6', 'Common cold', 15.00); 

select* from SERVICETable; 


Create Table doctortable(
DocID char (5) NOT NULL, 
DoctorFirstName char(15) Not NULL, 
DoctorLastName char (15) Not Null, 
DoctorPhone char (15) Not Null, 
CONSTRAINT DoctorTable_PK Primary Key(DocID)); 


INSERT INTO doctortable values 
('D1','Tim','Edward','555-123-4567'), 
('D2','Andy','Smith','888-777-6666'), 
('D3','John','Smith','222-321-7654'); 






Select * From doctortable; 



Create Table visit(
VisitID char (2) not Null, 
PatientID Char (5) not null, 
DocID Char (5) not null, 
ServiceID Char (5) not Null, 
RoomID char (2) not Null, 
Visit date not null, 
CONSTRAINT VISIT_PK PRIMARY KEY (VisitID)); 



Alter table Visit 
add foreign key (PatientID) 
references Patient (PatientID); 


Alter table Visit 
add foreign key (DocID) 
references doctortable (DocID); 

Alter table Visit 
add foreign key (ServiceID) 
references ServiceTable (ServiceID); 

Alter table Visit 
add foreign key (RoomID) 
references roomtableS (RoomID); 


Insert into Visit (VisitID,RoomID,ServiceID,PatientID,Visit) values 
**('1','P1','D1','S1','05','2014-01-03'), 
('2','P2','D2','S2','01','2014-01-10'), 
('3','P3','D1','S3','02','2014-01-10'), 
('4','P4','D2','S4','07','2014-01-15'), 
('5','P1','D3','S2','08','2014-01-10'), 
('6','P5','D3','S5','03','2014-02-02'), 
('7','P4','D1','S6','06','2014-01-10'), 
('8','P3','D2','S5','03','2014-02-03'), 
('9','P2','D3','S6','01','2014-02-04'), 
('10','P3','D1','S2','06','2014-02-04'), 
('11','P5','D2','S4','04','2014-02-05'), 
('12','P4','D1','S5','09','2014-02-06');** 
Select * from Visit; 
+1

'방문'표를 다시 확인하십시오. 당신은 5 컬럼을 언급했지만 그 값에는 6 컬럼이 있습니다. 그리고 여기에 질문을 올리기 전에 코드를 우선시하십시오. Stackoverflow에 오신 것을 환영합니다! :) –

+0

[MySql Workbench 오류 1452는 외래 키 제약 조건이 적용되지 않은 자식 행을 추가하거나 업데이트 할 수 없습니다.] (http://stackoverflow.com/questions/23045675/mysql-workbench-error-1452-cannot-add-or) -update-a-child-row-a-foreign-key-constr) –

답변

1

마지막 삽입 두 가지 문제가 있습니다 :

내가 실행 코드는 다음과 같습니다 방문 테이블 코드 분야 DOCID가 누락되어 있지만 값이 있습니다; 필드와 값 사이의 순서가 일치하지 않습니다. 당신은 sqlfiddle에서 전체 작업 코드를 찾을 수

Insert into Visit (VisitID,PatientID, DocID, ServiceID, RoomID,Visit) values 
('1','P1','D1','S1','05','2014-01-03'), 
('2','P2','D2','S2','01','2014-01-10'), 
('3','P3','D1','S3','02','2014-01-10'), 
('4','P4','D2','S4','07','2014-01-15'), 
('5','P1','D3','S2','08','2014-01-10'), 
('6','P5','D3','S5','03','2014-02-02'), 
('7','P4','D1','S6','06','2014-01-10'), 
('8','P3','D2','S5','03','2014-02-03'), 
('9','P2','D3','S6','01','2014-02-04'), 
('10','P3','D1','S2','06','2014-02-04'), 
('11','P5','D2','S4','04','2014-02-05'), 
('12','P4','D1','S5','09','2014-02-06'); 

: 같은

그것은해야합니다.