Creating New SQL Database And Table With Azure
IntroductionIn 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.
PrerequisitesAzure Account: If you don’t have free account, you can create from this link . SQL Server 2014 or above.
Create new SQL Database on AzureUsing 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 AzureIf 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 ruleYou 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 DatabaseNow, 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）相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术