Archive for March 2012

Storing and Retrieving data in SQL SERVER

In the earlier sessions we saw various ways how we can create tables.

Lets assumes that I have create a table to store my friends contact details. Here is the statement which I used to create table:


After executing that statement in SQL Server Query window, check whether table is created or not:

Run sp_help command in Query window. If FRIENDS table exists in the database , then sp_help text will result the following output:

Once the table is created, then store the data in the table.

Storing or Inserting data into a table:

Data can be inserted into a table through 2 ways.

  1. Using INSERT Command
  2. Using UI
INSERT Command:

 INSERT Command will be used to insert table in SQL SERVER.

Syntax for the INSERT command is as follows:

INSERT INTO <Table Name> ( Column1 ,Column2, Column3,......,ColumnN)
VALUES (Val1, Val2,Val3,.............,ValN)


Above query stores SAM Contact details in FRIENDS table.

Here for sample, I am inserting 5 records into FRIENDS table

Storing Data from UI:

Follow the below easy steps as listed in the below pictures to insert data into FRIENDS table from UI( User Interface).

  • Right Click on the table name and click on " Open Table"

    • When you open the table screen will look as follows:

    • Insert the details of the friends whose contact you want to store in FRIENDS table. Lets say I want to insert my friend RICK details here:

    Just enter your friends details in the above table. It will automatically be stored in the database.

    So, Now we are done with data insertion or storing in database.

    Data Retrieval:

    Here comes the point, How we can retrieve that data which we stored so far.

    After all database is all about storing , manipulating and retrieval of data.

    We can see that data that is stored in the table by opening the table as shown in step 1 of data storing using UI.

    Other way to retrieve data is using SELECT Command.

    Here is the syntax of SELECT Command:

    SELECT * FROM <Table Name>

    * should be used only if you want all the columns data from the table.

    We will lean more about SELECT command in coming sessions. For now, Lets stick to Select * from < Table Name>

    Base on the above syntax, The command for our situation would be:

    SELECT * FROM FRIENDS. Here is the result of that command:


    In this session we have learnt simple data storing and retrieval operations

    Commands used in this session are :


    Posted in | Leave a comment


    So far in the earlier blogs i have discussed various ways to create table. In this blog I will Summarise what all we have learnt in the previous sessions about Tables.

    • Tables are the Building blocks of any database.
    • Data ( any piece of information) in SQL Server or in any other database will be stored in tables.
    • Tables are composed of rows and columns.Data in the table is stored in rows and columns. Each Row and Column in table holds specific information.
    • Command used to create table is : CREATE TABLE < Table Name> ( Columns...)
    • Table creation is a DML Command.

    We will learn more about data integrity, normalisation forms of database, Keys, indexes,stored procedures , triggers and many more in the comings sessions.

    Keep watching this space for more tips and tricks in SQL Server.

    Posted in | Leave a comment