...

/

Retrieving Data from Tables

Retrieving Data from Tables

Learn to extract data from database tables using SELECT.

There is no use in having data if we cannot view it and work with it. We can use the SELECT command to retrieve data from tables in a database. Just like with inserting, there are several ways we can use this command.

Retrieve data from all columns

To retrieve all columns, we use this syntax:

SELECT * FROM TableSchema.TableName;

Let’s create the dbo.Students table, insert some data, and retrieve it afterward:

CREATE DATABASE LearningManagementSystem;
USE LearningManagementSystem;

CREATE TABLE Students
(
    Id INT PRIMARY KEY IDENTITY(1, 1),
    Name NVARCHAR(100) NOT NULL,
    BirthDate DATETIME NOT NULL,
    Address NVARCHAR(100) NOT NULL,
    PhoneNumber VARCHAR(15) NULL
);

INSERT INTO dbo.Students (Address, Name, BirthDate)
VALUES ('Bishkek, Kyrgyzstan', 'Aidil Umarov', '1996-09-06');

-- Selecting all columns of the table
SELECT * FROM dbo.Students;
Retrieving data from all columns

Retrieving all columns with * is not the best method of doing this, as we don’t usually need all ...