Create a simple Database and Table with some data in SQL Server

This is  for my testing and re-blogging purpose, I just want to create a database table and then insert few values. The reason I need this database, to create a BDC (Business Data Catalog) in SharePoint 2007. If anyone need to create a sample database then you can simply execute these scripts. 🙂

Step 1: Create a database

CREATE DATABASE Database1

Step 2: Create a Table

CREATE TABLE Table1(
Column1 int Primary Key NOT NULL,
Column2 varchar(10)
)

Step 3: Insert values into the table

INSERT INTO Table1 (Column1, Column2) VALUES (1, 'A')
INSERT INTO Table1 (Column1, Column2) VALUES (2, 'B')
INSERT INTO Table1 (Column1, Column2) VALUES (3, 'C')
INSERT INTO Table1 (Column1, Column2) VALUES (4, 'D')
INSERT INTO Table1 (Column1, Column2) VALUES (5, 'E')
INSERT INTO Table1 (Column1, Column2) VALUES (6, 'F')

That’s all, we will execute these two scripts (1 and then 2)

Script 1:

IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'Database1')
CREATE DATABASE Database1
GO

Script 2:

Use Database1
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'Table1'))
CREATE TABLE Table1(
Column1 int Primary Key NOT NULL,
Column2 varchar(10)
)
GO

INSERT INTO Table1 (Column1, Column2) VALUES (1, 'A')
INSERT INTO Table1 (Column1, Column2) VALUES (2, 'B')
INSERT INTO Table1 (Column1, Column2) VALUES (3, 'C')
INSERT INTO Table1 (Column1, Column2) VALUES (4, 'D')
INSERT INTO Table1 (Column1, Column2) VALUES (5, 'E')
INSERT INTO Table1 (Column1, Column2) VALUES (6, 'F')
GO

Copy and Paste these scripts in a Query Analyzer and execute from the menu or just press F5 to run the script!


Thanks. R./

Advertisements

,

  1. #1 by Web page on January 7, 2014 - 7:28 am

    Wow! At last I got a webpage from where I be capable of truly obtain
    useful data regarding my study and knowledge.

  1. Create a simple Database and Table with some data in SQL Server « Step Bi Step « Sutoprise Avenue, A SutoCom Source
  2. Create an Application Definition File (ADF) using Application Definition Designer (ADD) « Step Bi Step
  3. Creating Business Data Catalog(BDC) using Application Definition File(ADF) – SharePoint 2007 « Step Bi Step

Please leave a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: