how to query sql database

Azure SQL Database: Use SQL Server Management Studio to connect and query data
March 10, 2017 – 08:23 am
SSMS: Connect and query data in Azure SQL Database | Microsoft Docs
  1. Open SQL Server Management Studio.
  2. In the Connect to Server dialog box, enter the following information:

    Setting       Suggested value Description 
    Server type Database engine This value is required.
    Server name The fully qualified server name The name should be something like this: mynewserver20170313.database.windows.net.
    Authentication SQL Server Authentication SQL Authentication is the only authentication type that we have configured in this tutorial.
    Login The server admin account This is the account that you specified when you created the server.
    Password The password for your server admin account This is the password that you specified when you created the server.
  3. Click Options in the Connect to server dialog box. In the Connect to database section, enter mySampleDatabase to connect to this database.

  4. Click Connect. The Object Explorer window opens in SSMS.
  5. In Object Explorer, expand Databases and then expand mySampleDatabase to view the objects in the sample database.

Query data

  1. In Object Explorer, right-click mySampleDatabase and click New Query. A blank query window opens that is connected to your database.
  2. In the query window, enter the following query:

    SELECT pc.Name as CategoryName, p.name as ProductName FROM [SalesLT].[ProductCategory] pc JOIN [SalesLT].[Product] p ON pc.productcategoryid = p.productcategoryid;

  3. On the toolbar, click Execute to retrieve data from the Product and ProductCategory tables.

Insert data

  1. In the query window, replace the previous query with the following query:

    INSERT INTO [SalesLT].[Product] ( [Name] , [ProductNumber] , [Color] , [ProductCategoryID] , [StandardCost] , [ListPrice] , [SellStartDate] ) VALUES ('myNewProduct' , 123456789 , 'NewColor' , 1 , 100 , 100 , GETDATE );

  2. On the toolbar, click Execute to insert a new row in the Product table.

Update data

  1. In the query window, replace the previous query with the following query:

    UPDATE [SalesLT].[Product] SET [ListPrice] = 125 WHERE Name = 'myNewProduct';

  2. On the toolbar, click Execute to update the specified row in the Product table.

Delete data

  1. In the query window, replace the previous query with the following query:

    DELETE FROM [SalesLT].[Product] WHERE Name = 'myNewProduct';

  2. On the toolbar, click Execute to delete the specified row in the Product table.
Source: docs.microsoft.com
Related Posts