Introduction:
In this article we are going to see how to do an import database scripts available in SQL Azure management portal.
Overview:
We have seen in our earlier articles on how to manage a database by creating tables, views, stored procedures directly in the azure portal, now we are going to see on the options available to Import an existing available scripts to run on the azure portal.
[more]In a traditional SQL Server locally we will create all the scripts and run the required scripts on to the server-based on the needs, similar wise we can import the whole script to the Azure portal and use it as per our requirement. Let us see on the options how to do an import using the Azure portal step by step
Steps:
Log in to the Azure portal using the below link. You can see the screen look similar to below
http://www.microsoft.com/windowsazure/
Login to the portal using your Microsoft Windows Live credentials with Azure credentials to the management portal and you will see the screen as shown in the screen below
Now we can see the Database Menu at the bottom left, Click on that will go to the Database Subscription window as shown in the screen below
Clicking on the subscription name will provide the complete details of the server created and the new database created as shown in the screen below
Now we are going to create a new database using some scripts which we prepared locally. In our sample we have scripts to create small table, view and a stored procedure to import it to Azure database.
Script:
CREATE TABLE [dbo].[Employees](
[EmployeeID] [int] IDENTITY(1,1) NOT NULL,
[LastName] [nvarchar](20) NOT NULL,
[FirstName] [nvarchar](10) NOT NULL,
[Title] [nvarchar](30) NULL,
[TitleOfCourtesy] [nvarchar](25) NULL,
[BirthDate] [datetime] NULL,
[HireDate] [datetime] NULL,
[Address] [nvarchar](60) NULL,
[City] [nvarchar](15) NULL,
[Region] [nvarchar](15) NULL,
[PostalCode] [nvarchar](10) NULL,
[Country] [nvarchar](15) NULL,
[HomePhone] [nvarchar](24) NULL,
[Extension] [nvarchar](4) NULL,
[Photo] [image] NULL,
[Notes] [ntext] NULL,
[ReportsTo] [int] NULL,
[PhotoPath] [nvarchar](255) NULL
)
CREATE TABLE [dbo].[Customers](
[CustomerID] [nchar](5) NOT NULL,
[CompanyName] [nvarchar](40) NOT NULL,
[ContactName] [nvarchar](30) NULL,
[ContactTitle] [nvarchar](30) NULL,
[Address] [nvarchar](60) NULL,
[City] [nvarchar](15) NULL,
[Region] [nvarchar](15) NULL,
[PostalCode] [nvarchar](10) NULL,
[Country] [nvarchar](15) NULL,
[Phone] [nvarchar](24) NULL,
[Fax] [nvarchar](24) NULL
)
CREATE TABLE [dbo].[Products](
[ProductID] [int] IDENTITY(1,1) NOT NULL,
[ProductName] [nvarchar](40) NOT NULL,
[SupplierID] [int] NULL,
[CategoryID] [int] NULL,
[QuantityPerUnit] [nvarchar](20) NULL,
[UnitPrice] [money] NULL ,
[UnitsInStock] [smallint] NULL,
[UnitsOnOrder] [smallint] NULL ,
[ReorderLevel] [smallint] NULL ,
[Discontinued] [bit] NOT NULL
)
Create view [dbo].[Current Product List] AS
SELECT Product_List.ProductID, Product_List.ProductName
FROM Products AS Product_List
WHERE (((Product_List.Discontinued)=0))
Once we are ready with the script we will save it in a file Database Script.sql and now we are ready to do an import.
Now let us create a database (Check my earlier article on how to create a database in SQL Azure portal). Once the database is created your screen will look like below
Now go to the Manage portal by clicking on the Manage button on the top menu as shown in the screen below
Now we are prompted to enter the credentials to login to the server as shown in the screen below. This is some like while we enter SQL Server Management Studio we will be asked to enter the login credentials
Once we entered valid credentials our page will look like below with the new SQL Azure Management portal
Now we have script ready to import to the SQL Azure database we can do that by going to OPEN QUERY window as shown in the screen below
Now it will open the window to select the file as shown in the screen below
Select the file and Click on Open will open the scripts in the Azure portal window as shown in the screen below
Now Select the appropriate tables and click on Execute button at the top to execute the table, views and stored procedures separately. Else if we have scripts arranged in correct order we can execute it as a whole as shown in the screen below
Now we can see the commands are executed correctly. We can check the new tables by going to each section menu at the left side as shown in the screen below
Before doing that we need to click on the refresh button in order to refresh the Schema and get the latest changes as shown in the screen below
Now we can see the new tables and the views added in the list as shown in the screen below
Conclusion:
So in this article we have seen on how to do an import database script option using SQL Azure Management Portal