Answers

Question and Answer:

  Home  MS SQL Server

⟩ How to read data in a table with "SELECT" statements?

Now this part is for creating database objects with Transact-SQL statements. This Question shows you how to create a database, create a table in the database, and then access and change the data in the table. Because this Answer is an introduction to using Transact-SQL, it does not use or describe the many options that are available for these statements. This Guide assumes that you are running SQL Server Management Studio Express.

Use the SELECT statement to read the data in a table. The SELECT statement is one of the most important Transact-SQL statements, and there are many variations in the syntax. For this Answer, you will work with five simple versions.

To read the data in a table - Type and execute the following statements to read the data in the Products table.

-- The basic syntax for reading data from a single table

SELECT ProductID, ProductName, Price, ProductDescription

FROM dbo.Products

GO

You can use an asterisk to select all the columns in the table. This is often used in ad hoc queries. You should provide the column list in you permanent code so that the statement will return the predicted columns, even if a new column is added to the table later.

-- Returns all columns in the table

-- Does not use the optional schema, dbo

SELECT * FROM Products

GO

 154 views

More Questions for you: