How to Share Data between Stored Procedures

 

http://www.sommarskog.se/share_data.html

 

Querying the SQL Server System Catalog

http://msdn.microsoft.com/en-us/library/ms189082(v=sql.90).aspx

질문

We are writing a new application, and while testing, we will need a bunch of dummy data. I've added that data by using MS Access to dump excel files into the relevant tables.

Every so often, we want to "refresh" the relevant tables, which means dropping them all, re-creating them, and running a saved MS Access append query.

The first part (dropping & re-creating) is an easy sql script, but the last part makes me cringe. I want a single setup script that has a bunch of INSERTs to regenerate the dummy data.

I have the data in the tables now. What is the best way to automatically generate a big list of INSERT statements from that dataset?

I'm thinking of something like in TOAD (for Oracle) where you can right-click on a grid and click Save As->Insert Statements, and it will just dump a big sql script wherever you want.

The only way I can think of doing it is to save the table to an excel sheet and then write an excel formula to create an INSERT for every row, which is surely not the best way.

I'm using the 2008 Management Studio to connect to a SQL Server 2005 database

 

답변

As mentioned by @Mike Ritacco but updated for SSMS 2008 R2

  1. Right click on the database name
  2. Choose Tasks > Generate scripts
  3. Depending on your settings the intro page may show or not
  4. Choose 'Select specific database objects',
  5. Expand the tree view and check the relevant tables
  6. Click Next
  7. Click Advanced
  8. Under General section, choose the appropriate option for 'Types of data to script'
  9. Complete the wizard

You will then get all of the INSERT statements for the data straight out of SSMS

'SQL Server' 카테고리의 다른 글

유용한 사이트  (0) 2014.07.28
원격 SQL Server 연결문자열 작성  (0) 2014.06.24

1. 설치시에 sa의 암호를 설정하여 설치한다. 이 때 윈도우와 SQL 혼합 인증을 하도록 한다.
2. 설치를 마치면 시작->프로그램->MS SQL Server 2008 R2 ->구성 도구 -> 구성 관리자를 실행한다
3. 구성관리자 아래쪽에 있는 SQL Server 네트워크 구성을 선택한다.
4. SQLEXPRESS에 대한 프로토콜을 선택한다.
5. 거기서 TCP/IP와 명명된 파이프 두 가지를 사용으로 변경한다.
6. TCP/IP의 등록정보를 열어 IP 주소 탭의 아래쪽에 있는 IP ALL에서 TCP 포트를 1433으로 지정해 준다.
7. SQL Server 서비스 및 browser 서비스를 실행시 자동으로 바꾸고 재시작 한다.
8. 방화벽 설정으로 들어간다.(시작 + R -> firewall.cpl )
9. 방화벽에 예외 허용이 되어 있는지 확인을 하고 예외에서 다음의 설정을 해준다.
   예외 포트 등록 : TCP 1433, UDP 1434
   예외 프로그램 등록 : [SQLServr.exe] <-- 오타 아님 (경로는 대략 \Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn\sqlservr.exe)
                       [SQLBrowser.exe] (대락적인 경로는 \Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe)
10. management studio를 실행하여 왼쪽 트리뷰의 서버에서 우클릭하여 속성 선택한다.
11. 연결 탭에 외부 원격 접속 허용 부분을 체크한다.

 

 

설치시 1번을 하지 않았을 경우나 다른 계정 사용을 원할 경우, 보안->로그인에 새 사용자를 등록하거나, sa 에 대한 설정을 변경할 수 있다.

이때 상태 탭에서 로그인을 사용. 연결 권한을 허용 으로 해야한다.

'SQL Server' 카테고리의 다른 글

유용한 사이트  (0) 2014.07.28
테이블데이터 하나하나에 대하여 insert 문 생성하기  (0) 2014.06.27

+ Recent posts