Export (0) Print
Expand All

Walkthrough: Creating a Sample Server Database [Tutorial]

Sync Framework 2.1

In this walkthrough you will create a sample SQL Server database that you will use later in a synchronization scenario. The following list contains the detailed steps to create the database.

  1. Launch SQL Server Management Studio: Click Start, point to Programs, point to Microsoft SQL Server 2008, and then click SQL Server Management Studio. Use similar steps if you are using SQL Server 2005 or SQL Server 2008 R2 to launch SQL Server Management Studio for that specific version.

  2. Connect to SQL Server by using appropriate credentials: On the Connect to Server dialog box, select Database engine for Server type, select a SQL Server instance for Server name, and use appropriate authentication settings to connect to the server.

  3. Click New Query on the toolbar or press Ctrl+N to launch a query window.

  4. Copy the following SQL code to the query editor.

    USE [master] 
    GO
     
    IF EXISTS(SELECT name FROM sys.databases WHERE name = 'SyncDB') 
        DROP DATABASE SyncDB
     
    CREATE DATABASE [SyncDB] 
    GO
     
    USE [SyncDB] 
    GO
     
    CREATE TABLE [dbo].[Products](
        [ID] [int] NOT NULL, 
        [Name] [nvarchar](50) NOT NULL, 
        [ListPrice] [money] NOT NULL
     
        CONSTRAINT [PK_Products] PRIMARY KEY CLUSTERED ([ID] ASC) 
    ) 
    GO
     
    CREATE TABLE [dbo].[Orders]( 
        [OrderID] [int] NOT NULL, 
        [ProductID] [int] NOT NULL, 
        [Quantity] [int] NOT NULL, 
        [OriginState] [nvarchar](2) NOT NULL, 
        CONSTRAINT [PK_Orders] PRIMARY KEY CLUSTERED ([OrderID] ASC,[ProductID] ASC) 
    ) 
    GO
     
    ALTER TABLE [dbo].[Orders]  WITH CHECK ADD  CONSTRAINT [FK_Orders_Products] FOREIGN KEY([ProductID]) 
    REFERENCES [dbo].[Products] ([ID]) 
    GO
     
    ALTER TABLE [dbo].[Orders] CHECK CONSTRAINT [FK_Orders_Products] 
    GO
     
    INSERT INTO Products VALUES (1, 'PC', 400) 
    INSERT INTO Products VALUES (2, 'Laptop', 600) 
    INSERT INTO Products VALUES (3, 'NetBook', 300) 
     
    INSERT INTO Orders VALUES (1, 1, 2, 'NC') 
    INSERT INTO Orders VALUES (2, 2, 1, 'NC') 
    INSERT INTO Orders VALUES (3, 1, 5, 'WA') 
    INSERT INTO Orders VALUES (3, 3, 10, 'WA') 
    INSERT INTO Orders VALUES (4, 2, 4, 'WA')
    
  5. Press F5 to execute the query.

  6. In the Object Explorer window, right-click <database name> and click Refresh. Expand Databases, and confirm that SyncDB database is created with two tables: dbo.Products and dbo.Orders.

  7. Keep SQL Server Management Studio open.

Show:
© 2014 Microsoft