DML Commands in SQL Server: SELECT

DML: Data Manipulation Language

In the earlier sessions, we have seen how to INSERT data into a table and How to UPDATE data in the table.

The main purpose of the database is to store and retrieve date.

Once data is inserted/updated ( stored ) in the database, then our next goal is to fetch(retrieve) the data which we stored earlier.

In this article we will see simple SELECT command . SELECT Command can go with many other command like WHERE, GROUP BY, HAVING, ORDER BY, TOP, DISTINCT, COUNT etc., I will explain in detail about all these commands in coming session. For now, lets limit this session to a simple SELECT Command.

Here is the Simple SELECT Command Syntax in SQL SERVER.

Syntax:
  1. SELECT * FROM <Table Name>   : This command retrieves complete data from the table (i.e, information from all the columns).
  2. SELECT Col1, Col2,Col3,....ColN FROM <Table Name>: This command retrieves the data from only the columns which are used in the select command.
Lets see the examples for both the above syntax formats:

Assume that we have a table (MYPASSWORDS) with the following information. This table contains list of my email ids and corresponding passwords.

ACCOUNTACCOUNTIDPWD
GMAILcatchme@gmail.comasderuom09
GMAILsqldeveloper@gmail.comsqlpor739
GMAILsqldeveloper@gmail.comsqlpor739
YAHOLmyyahooid@yahoo.comolju67
YAHOLsqlmyid@yahoo.comitryry67


Execute the command given in Syntax 1: (SELECT * FROM MYPASSWORDS) . Result set for this query is given below:












Execute the command given in Syntax 2: (SELECT ACCOUNID,PWD FROM MYPASSWORDS) . Result set for this query is given below. This will fetch only Account Id and password from the table.



Summary:

This article describes how to use SELECT command for simple data retrieval.

This entry was posted in . Bookmark the permalink.

Leave a reply