/* Author...: Michael Thomas email....: michael@michael-thomas.com Date.....: 05/16/06 Modified.: 07/14/07 Used for the examples at: www.michael-thomas.com for MSSQL Commands. Description: Example of using Cursors. */ use master IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'MyTempDB') begin DROP DATABASE [MyTempDB] end go create database MyTempDB go use MyTempDB -- ************************** -- MyTable -- ************************** if exists (select * from [dbo].[sysobjects] where id = object_id(N'MyTable') ) begin drop table MyTable end go -- Table that has an ID that is created automatically. create table MyTable ( id int IDENTITY(1,1) not null, code char(1), codedesc nvarchar(255) ) go -- Inserts where all you need to do is add a select. insert into MyTable ( code, codedesc ) select 'A', 'Hello World 1' union all select 'B', 'Hello World 2' union all select 'C', 'Hello World 3' -- Standard inserts. insert into MyTable ( code, codedesc ) values ('D', 'Hello World 4') insert into MyTable ( code, codedesc ) values ('E', 'Hello World 5') insert into MyTable ( code, codedesc ) values ('F', 'Hello World 6') go select * from MyTable