How Can I do 1 Click Execute This T-SQL

Burak KILIÇ

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

T-sql Error

D-Shih

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.

edited at
0

Comments

0 comments
Login to comment

Related

I can't execute SQL sentence twice

How can i modify this sql for execute?

How can I execute multiple functions on click(or on change) in sibling components?

How to close menu when i click option? easy JS but i can't do that :/

How can I make LinqPad show me all results without the need to "click" "List<T>" hyperlink to get the query to execute?

Why can't I do ls -a 1>&-?

How can I condition a button click not to execute, if the click is not immediately released in Python?

SQL Server can't execute

How can I execute 2 functions on 1 route in Laravel?

How can I execute the SQL query first then the rest of the code?

How can I execute this sql statement with .NET and Dapper.NET?

How can I execute a SQL insert in a wizard active step?

How can I execute a comand if condition is true (SQL)

How can I execute SQL scripts using TeamCity?

How can I execute SQL and get results from PHP?

How can I execute SQL scripts via Powershell?

How do I execute a SQL script using a bind variable

How do I execute a SQL statement with parameters in ServiceStack.OrmLite?

How do I execute a dynamic SQL with over 8000 Characters?

How do I execute/run a .sql file in PostgreSQL 9.2.6 + CentOs

How can I do "double-aggregation" in T-SQL / SQL Server?

How do I kill connections to Azure SQL database if I can't access it?

Using Blazor with Electron.NET, how can I execute code inside a component whenever I click on a MenuItem?

Can't click on SQL Profiler

How can I do this as 1 database query?

How can I click button every 1 seconds?

I can't click on an element

How can I do this SQL query correctly?

How can I do this in SQL/phpmyadmin?

TOP Ranking

HotTag

Archive