2014-07-23 1 views
0

내 주요 select 문을 사용하기 전에 먼저 수천 줄의 임시 테이블을 만들어야합니다 (SQL Server 환경에서는 이러한 명령 줄을 자동으로 실행할 수없는 select 문을 사용). 그러나 SQL 쿼리는 악몽입니다 가독성의 내 .SQL 파일로 대신의 SQL 쿼리에 SQL 코드를 포함시키는 방법은 무엇입니까?

include('actors_tables.sql') /*including all the insert code*/ 
select * from #temp_actors 

?

create table #temp_actors (firstname varchar(50), lastname varchar(50)) 
insert into #temp_actors values ('George','Clooney') 
insert into #temp_actors values ('Bill','Murray') 
insert into #temp_actors values ('Bruce','Willis') 
... + 1000 inserts in thousands of lines 
select * from #temp_actors 

는 같은 날 것 같다? 라인 :(

인가 이런 식으로 뭔가를 달성 할 수의 수천이있다기본 간단한 기능을하지만이 방법을 찾을 수 없습니다. 서버에서 SQL Server 2005를 실행하고 SQL Server Management Studio 2008을 사용하고 있습니다.

감사합니다.

Kris.

답변

0

, 시작 을 SQLCMD :

sqlcmd -S <server> -i C:\<your file name here>.sql -o 

또는 을 xp_cmdshell을하고 SQLCMD 사용 SQL 서버 관리 스튜디오에서 실행 : 불행하게도 cp_cmdshell가 비활성화 된

EXEC xp_cmdshell 'sqlcmd -S ' + @DBServerName + ' -d ' + @DBName + ' -i ' + @FilePathName 
+0

을 내 작업 환경에서 감사/보안상의 이유로. – kriskaido

0

입력 파일과 함께 명령 프롬프트에서 Sqlcmd을 사용할 수 있습니다 (sqlcmd -i actors_tables.sql 사용).

명령 프롬프트에서
관련 문제