Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Wednesday, May 6, 2009

How to connect to SQL Server 2008 using 2005

While supporting the website калькулятор на автокредит I encountered a problem when I use SQL Server Management Studio in SQL Server 2005 to connect to an instance of SQL Server 2008.
To solve this problem, I installed Microsoft SQL Server 2005 Service Pack 2. After that I also installed "Cumulative update package 12 for SQL Server 2005 Service Pack 2 (server and client)".
And, voila, it works!

Tuesday, February 3, 2009

LINQ to SQL: How to get a Random Record from a Table inside the SQL Server Database

I wanted to get a random record from a particular table on the SQL Server database. For my case, I had a table containing quotes, and I wanted to randomly pick on to show on one corner of my web site. I am also using LINQ to SQL for this web site, so the solution here will be using LINQ, although the approach is pretty simple and flexible.

The idea centers on ordering the records by a random parameter an then getting the TOP n number of records. The NEWID() function from SQL Server makes a great candidate for getting a random parameter since this method generates a GUID.

In SQL Server, try out this query.


SELECT * FROM Quote ORDER by NEWID();


SELECT TOP 1 * FROM Quote ORDER by NEWID();

Tuesday, January 6, 2009

How to reduce the size of the database in Microsoft SQL Server

On hosting server often exists database quota for MS SQL Server. Even if your database contains small amount of data, but there is goes intensive adding/modifacation of the data, in some point the size of the data could exceed quota and your account may be suspended.
This happens because of growth of the transaction log.
To clear transaction log you can execute the following command: