Showing posts with label Query. Show all posts
Showing posts with label Query. Show all posts

Sunday, 27 September 2009

Display information from a table and change the column names

In my database table I have two columns : ProdID and Prod. When I query the database to display the IDs and the product names, I would like to make the result a bit more 'User friendly' by changing the column names to 'Product ID and 'Product'. I do this in the following way :


Open query analyser.
Select the required database.

Select ProdID as 'Product ID', Prod as Products from Inventory

How do you copy a database table in SQL using code?

Open Query analyser
Select the required database (Use [databasename])

Type :

SELECT * INTO MyNewTable FROM MyTable

e.g SELECT * INTO Customer2 FROM Customer

How do you select all items from a SQL table ?

This is probably the first thing you will ever do with SQL and it's a nice easy one to get you started.

Open query analyser.
Select the required database (This can be done from the drop down menu or by typing "Use [database name"])

Type :

Select * from [table name]

This will now return all the records in the table.