I'm using SQL 2012 and I want all code to work at once. But giving me this error. How should I follow a path. Thanks.
BEGIN
USE [DLSaglikNet]
CREATE TABLE PASSAPORT_TURU
(
ID int NOT NULL PRIMARY KEY IDENTITY (1,1),
ADI varchar(70) ,
KODU varchar(20)
)
INSERT INTO PASSAPORT_TURU (ADI,KODU)
VALUES
('Passaport Numarası','1'),
('Yabancı Hasta T.C. Kimliği','2'),
('Lütfen Seçim Yapınız.','3')
Alter table HASTA Add PASSAPORTTURU int CONSTRAINT FK_HASTA_PASSAPORT_TURU foreign key (PASSAPORTTURU) REFERENCES PASSAPORT_TURU(ID)
Update HASTA set PASSAPORTTURU = 1 where PASSAPORT IS NOT NULL and TCKIMLIK IS NULL and PASSAPORTTURU IS NULL
Update HASTA set PASSAPORTTURU = 3 where PASSAPORT IS NULL and TCKIMLIK IS NOT NULL
END;
GO
When you doing DDL statement you need to use GO
keyword after it, which mean execution of batches and scripts.
These commands can be used to facilitate the readability and execution of batches and scripts.
make sure
Alter table HASTA Add PASSAPORTTURU int CONSTRAINT FK_HASTA_PASSAPORT_TURU foreign key (PASSAPORTTURU) REFERENCES PASSAPORT_TURU(ID)
was executed before insert the data.
BEGIN
USE [DLSaglikNet]
CREATE TABLE PASSAPORT_TURU ( ID int NOT NULL PRIMARY KEY IDENTITY (1,1), ADI varchar(70) , KODU varchar(20) )
INSERT INTO PASSAPORT_TURU (ADI,KODU) VALUES ('Passaport Numarası','1'), ('Yabancı Hasta T.C. Kimliği','2'), ('Lütfen Seçim Yapınız.','3')
Alter table HASTA Add PASSAPORTTURU int CONSTRAINT FK_HASTA_PASSAPORT_TURU foreign key (PASSAPORTTURU) REFERENCES PASSAPORT_TURU(ID)
GO -- <-- ADD GO HERE.
Update HASTA set PASSAPORTTURU = 1 where PASSAPORT IS NOT NULL and TCKIMLIK IS NULL and PASSAPORTTURU IS NULL
Update HASTA set PASSAPORTTURU = 3 where PASSAPORT IS NULL and TCKIMLIK IS NOT NULL
END;.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments