Introduction
In this article, we will see in detail about how to create our first SQL Server database in Azure and creating a table for Azure SQL database from our SQL Server Management Studio.Prerequisites
Azure Account: If you don’t have free account, you can create from this link . SQL Server 2014 or above.Create new SQL Database on Azure
Using your Azure account, login to Azure site. From the dashboard page on the left side menu, we can see SQL databases. Click menu to create our first SQL database in Azure.
We can see the Add icon at the top. To create our fist SQL database, again click Add icon.

Here, we give our new database name and select or create our resource group.

Creating SQL Server on Azure
If we don’t have any SQL Server created, first we need to create a new SQL Server to create our database.Here, we give our new Server name, login ID and Password for login to our Azure SQL Server.

Once our Server was created, select the newly added SQL Server to create our database.

Click Create button at the bottom to create our new database on the selected Server. Now, we can see a confirmation message as Validation Successful.

We can see now our new database has been created.

We can see all the details for newly created database from the database dashboard page.

To know our Azure SQL connection, we can click on the “Show database connection strings”. We can see the connection string for ADO.NET, ODBC,php and JDBC. We can use this connection string in our technology Applications to connect Azure databases. For example, to work with Microsoft.NET, we can select ADO.NET for working with JSP or Java, we can use JDBC or ODBC and to work with PHP Application, we can use the PHP connection strings.

Connecting Azure SQL Serve from Local SQL Server
Now, we have created our SQL database in Azure. To create tables and insert sample records, we will use SQL Server Management studio to connect to our Azure Server.
We need to give our Azure SQL Server name with our given ID and password.

When we try to connect for the first time, we may get the error, as shown below-

This error is due to the Firewall rule, which is not set by the selected Azure Server.
Setting Azure SQL Server firewall rule
You can find “Set server Firewall” at the top. Click to set our Firewall rule.
Click “Add Client IP” to set our new Firewall rule.

Click save to add our new Firewall Setting

After saving the new Firewall setting, now again connect to our Azure SQL Server from our local SQL Server Management Studio.

Creating Tables for Azure SQL Database
Now, we have connected our Azure SQL Server. Let’s create tables and insert record in our Azure database.In Query Analyzer, run Create SQL script to create our tables, which is given below.
IFEXISTS(SELECT[name]FROMsys.tablesWHERE[name]='HotelMaster') DROPTABLEHotelMaster GO CREATETABLEHotelMaster ( RoomIDintidentity(1,1), RoomNoVARCHAR(100)NOTNULL, RoomTypeVARCHAR(100)NOTNULL, PrizeVARCHAR(100)NOTNULL CONSTRAINT[PK_HotelMaster]PRIMARYKEYCLUSTERED ( RoomIDASC )WITH(PAD_INDEX=OFF,STATISTICS_NORECOMPUTE=OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ON[PRIMARY] )ON[PRIMARY] InsertintoHotelMaster(RoomNo,RoomType,Prize)Values('101','Single','50$') InsertintoHotelMaster(RoomNo,RoomType,Prize)Values('102','Double','80$') select*fromHotelMaster IFEXISTS(SELECT[name]FROMsys.tablesWHERE[name]='RoomBooking') DROPTABLERoomBooking GO CREATETABLERoomBooking ( BookingIDintidentity(1,1), RoomIDint, BookedDateFRVARCHAR(20)NOTNULL, BookedDateTOVARCHAR(20)NOTNULL, BookingStatusVARCHAR(100)NOTNULL, PaymentStatusVARCHAR(100)NOTNULL, AdvancePayedVARCHAR(100)NOTNULL, TotalAmountPayedVARCHAR(100)NOTNULL, CONSTRAINT[PK_RoomBooking]PRIMARYKEYCLUSTERED ( [BookingID]ASC )WITH(PAD_INDEX=OFF,STATISTICS_NORECOMPUTE=OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ON[PRIMARY] )ON[PRIMARY] select*fromRoomBooking Now, we can see our new tables have been created in Azure SQL database.
本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术
本文标题:Creating New SQL Database And Table With Azure
本站链接:http://www.codesec.net/view/482948.html
分享请点击:
1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。