Azure Logo Microsoft Docs

Quickstart: Create and query Azure SQL Database

This quickstart guides you through the process of creating an Azure SQL Database and learning to query data with Transact-SQL (T-SQL).

Tip: You can use Azure Data Studio or SQL Server Management Studio (SSMS) to connect to your database. We'll use Azure Data Studio for this quickstart.

Prerequisites

Before you begin, ensure you have the following:

Steps

  1. Create an Azure SQL Database:

    Navigate to the Azure portal and select 'Create a resource'. Search for 'SQL Database' and click 'Create'. Fill in the required details, including a resource group, database name, server name, and administrative credentials. For this quickstart, you can use the default pricing tier.

  2. Connect to your database:

    Once the database is deployed, navigate to its resource page in the Azure portal. Under 'Settings', select 'Connection strings'. Copy the ADO.NET connection string (it will contain your server name, database name, and user ID). Open Azure Data Studio and create a new connection. Paste the connection string, enter your password, and click 'Connect'.

    Note: Ensure your firewall rules are configured to allow access from your IP address. You can configure this in the Azure portal under the SQL server's 'Networking' settings.
  3. Create a sample table:

    In Azure Data Studio, open a new query editor connected to your database. Execute the following T-SQL script to create a sample table named 'Products':

    
    CREATE TABLE Products (
        ProductID INT PRIMARY KEY IDENTITY(1,1),
        ProductName VARCHAR(100) NOT NULL,
        Category VARCHAR(50),
        Price DECIMAL(10, 2)
    );
                            
  4. Insert data into the table:

    Now, insert some sample data into the 'Products' table:

    
    INSERT INTO Products (ProductName, Category, Price) VALUES
    ('Laptop', 'Electronics', 1200.00),
    ('Desk Chair', 'Furniture', 250.00),
    ('Coffee Mug', 'Kitchenware', 15.50);
                            
  5. Query the data:

    Finally, query the data from the 'Products' table:

    
    SELECT ProductID, ProductName, Price FROM Products WHERE Price > 100;
                            

    You should see the 'Laptop' and 'Desk Chair' records returned.

Congratulations! You have successfully created an Azure SQL Database, connected to it, and performed basic data operations.

Next Steps

For more detailed information, refer to the full Azure SQL Database documentation.