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
In the Connect to Database Engine dialog box, type either localhost or the name of the local SQL Server instance, and then click Connect.
Paste the following Transact-SQL script in the query window and then click Execute.
USE master;GOIF DB_ID (N'AdventureWorks') IS NOT NULLDROP DATABASE AdventureWorks;GO-- Get the SQL Server data pathDECLARE @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 AdventureWorksON ( 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');GOGO
Refresh Explorer, Database AdventureWorks should be visible.
Next Step: Creating the Windows Forms Application
Back to QuickStart Home Page