Friday, March 19, 2010

Sleep for 1 min in SQL SERVER 2005

We just want to delay our query for one min.

To achieve that one we need write the below script

print getdate()
waitfor delay '00:01'
print getdate()


Output:

Mar 19 2010  6:37PM
Mar 19 2010  6:38PM



Happy Querying

Multiple Columns as Primary Key - SQL Server 2005

Steps to make multiple Columns of a table in SQL Server Management Studio

  1. Go to Table Design.
  2. Select a Column first to define it as Primary key.
  3. To select multiple columns, hold down the CTRL key while you click the other columns.
  4. Right-click the row selector for the column and select Set Primary Key.
  5. A primary key index, named "PK_" followed by the table name is automatically created.
Hope this helps you

Happy Coding

Wednesday, March 17, 2010

Update Tables Using Inner Join

You will come across the problem to update a table with the help of joining two tables.

Below is the steps to update a table using joins

  1. Perform a update say UPDATE
  2. Join the tables with condition say FIRSTTABLE AS A INNER JOIN SECONDTABLE AS B ON A.FIELDNAME = B.FIELDNAME
  3. Write the condition which is going to change or update say SET A.FIELDNAME=2, B.FIELDNAME=5
  4. If you have a where condition then add it say WHERE A.FIELDNAME=10
Combine the above steps and form a query as below
UPDATE
FIRSTTABLE AS A INNER JOIN SECONDTABLE AS B
ON A.FIELDNAME = B.FIELDNAME
SET A.FIELDNAME=2, B.FIELDNAME=5
WHERE A.FIELDNAME=10

Simply cool

Hope this helped you.

Happy Coding,
Kumar

Thursday, November 26, 2009

SQL Database Offline / Online

If the user wants to make the database offline or online below are the commands.

First Method:
To make database offline use the below query
ALTER DATABASE [Database name] SET OFFLINE

To make database online use the below query
ALTER DATABASE [Database name] SET ONLINE

Second Method:
User can also right click on the Database and select Tasks->Take Offline

select Tasks->Brink online for making Database to Online

blogger templates | Make Money Online