How to Write Basic SQL Statements in SQL Server

Download ArticleDownload Article

If you work with databases frequently, you might have to occasionally write basic SQL queries to retrieve and manipulate the data you need. The best way to write SQL commands is in SQL Server Management Studio. Luckily, it's pretty easy, even if you're a beginner to writing SQL. We'll show you some basic commands, like the SELECT statement, INSERT statement, and more!



1) SELECT - This command is used to retrieve information from a table

2) INSERT - This command is used to add information to a table

3) UPDATE - This command is used to modify information to a table

4) DELETE - This command is used to remove information from a table

  1. How.com.vn English: Step 1 WH.performance.clearMarks('image1_rendered'); WH.performance.mark('image1_rendered');...
    Click on Start --> All Programs --> Microsoft SQL Server (2005/2008) --> SQL Server Management Studio
  2. How.com.vn English: Step 2 Next Login with your credentials to the Server
    Advertisement
  3. How.com.vn English: Step 3 Now right click on the Northwind Database and choose New Query
  4. How.com.vn English: Step 4 In the new Query Window, enter the following command for SELECT
  5. How.com.vn English: Step 5 This is the syntax for SELECT - SELECT * FROM Employees
  6. How.com.vn English: Step 6 This is the...
    This is the syntax for INSERT -

    INSERT INTO Employees VALUES('col1', 'col2') - Replace col1 and col2 with actual Values as shown below

    INSERT INTO Employees values('Anil','[email protected]')
    This inserts a single row into the table.

    In the even you wish to enter multiple rows at one go, you see the following command

    INSERT INTO Employees values('Anna','[email protected]'), INSERT INTO Employees values('Krystel','[email protected]'), INSERT INTO Employees values('Lines','[email protected]'). The key difference here is that every value is appended by a comma
  7. Advertisement
    7
  8. How.com.vn English: ...
    This is the syntax for UPDATE - UPDATE Employees SET col1 = 'new value' WHERE col1 = 'old value' - Replace col1 with actual Values as shown below
  9. UPDATE Employees SET Name = 'Anil Mahadev' WHERE Name = 'Anil'
    How.com.vn English: ...
  10. This is the syntax for DELETE - DELETE FROM Employees WHERE col1 = 'value' WHERE value = 'actual data row' - Replace actual data row with actual Values as shown below
    How.com.vn English: ...
  11. DELETE FROM Employees WHERE Name = 'Anil Mahadev'
    How.com.vn English: ...
  12. This completes this short How-To, I hope this has been beneficial to you and like to Thank You for viewing it.
    How.com.vn English: Write Basic Sql Statements in Sql Server Step 11
  • Use the SQL Server Management Studio Code Snippets as hints to better your SQL Writing Skills
  • As you become more comfortable writing Queries, Use the SQL Query Designer to build sophisticated queries
  • Never use DELETE without a WHERE Clause in your Statements to prevent accidental deletion of rows
  • Same rule applies to UPDATE and INSERT as well
  • Always use Caution when working with the DELETE command.

Community Q&A

Search
Add New Question
  • Question
    Can you explain the steps from creation of a database to the retrieval of data from it?
    How.com.vn English: Community Answer
    Community Answer
    Database management is more complex than a single question and answer can explain. There are many free tutorials online. Start by googling "SQL tutorial" and see what you find.
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
      Advertisement

      About This Article

      How.com.vn is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 13 people, some anonymous, worked to edit and improve it over time. This article has been viewed 116,379 times.
      How helpful is this?
      Co-authors: 13
      Updated: November 23, 2021
      Views: 116,379
      Categories: Databases
      Thanks to all authors for creating a page that has been read 116,379 times.

      Is this article up to date?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement