Creating the AdventureWorks Database

In this task, you will create the schema for the AdventureWorks Database and load data into the database. 

To do this, you use SQL Server Management Studio or SQL Server Management Studio Express to execute a Transact-SQL script to attach mdf file of Database. 


  To create the database and schema

  1. Install AdventureWorksDB from here
  2. Launch SQL Server Management Studio 
  3. On the File menu, point to New, and then click Database Engine Query.
  4. In the Connect to Database Engine dialog box, type either localhost or the name of the local SQL Server instance, and then click Connect.

  5. Paste the following Transact-SQL script in the query window and then click Execute.

USE master;
GO
IF DB_ID (N'AdventureWorks') IS NOT NULL
DROP DATABASE AdventureWorks;
GO
-- Get the SQL Server data path
DECLARE @data_path nvarchar(256);
SET @data_path = (SELECT SUBSTRING(physical_name, 1, CHARINDEX(N'master.mdf', LOWER(physical_name)) - 1)
                  FROM master.sys.master_files
                  WHERE database_id = 1 AND file_id = 1);

-- execute the CREATE DATABASE statement 
EXECUTE ('CREATE DATABASE AdventureWorks
ON 
( NAME = AdventureWorks,
    FILENAME = '''+ @data_path + 'AdventureWorks_Data.mdf'',
    SIZE = 10,
    MAXSIZE = 50,
    FILEGROWTH = 5 )
LOG ON
( NAME = AdventureWorks_log,
    FILENAME = '''+ @data_path + 'AdventureWorks_log.ldf'',
    SIZE = 5MB,
    MAXSIZE = 25MB,
    FILEGROWTH = 5MB )
FOR ATTACH'
);
GO

GO

Refresh Explorer, Database AdventureWorks should be visible.

 

Next Step: Creating the Windows Forms Application

 

Back to QuickStart Home Page