Thursday, September 15, 2011

Shrink SQL Server 2008 Database Log File Script

I found this script to shrink the database log file in a SQL Server 2008 database. This procedure has changed, since the BACKUP command does not work the same way as previous versions.

Use DatabaseName
GO
Alter Database DatabaseName Set Recovery Simple
GO
Alter Database DatabaseName Set Recovery Full
GO
DBCC SHRINKFILE ('LogFileName', 1)
GO

Monday, July 18, 2011

How to Find Tables without Indexes?

Simply run the following query in the Query Editor.

USE database_name;
GO
SELECT SCHEMA_NAME(schema_id) AS schema_name,name AS table_name
FROM sys.tables
WHERE OBJECTPROPERTY(OBJECT_ID,'IsIndexed') = 0
ORDER BY schema_name, table_name;
GO

Thursday, July 7, 2011

Server Side Paging

In the previous post I wrote about OFFSET and FETCH on SQL Denali.

Today I want to write a sample to use them in a real world:
Normally to do paging on server we do this:

USE AdventureWorks
GO
DECLARE @NumberOfRows INT = 10 -- Number of rows you want on a page
DECLARE @DesiredPageNumber INT = 5 -- Page number
SELECT *
FROM
(
SELECT RowNum = ROW_NUMBER() OVER (
ORDER BY EmployeeID), *
FROM HumanResources.Employee
) AS a
WHERE RowNum > (@NumberOfRows * (@DesiredPageNumber - 1))
AND RowNum <= (@NumberOfRows * (@DesiredPageNumber - 1)) + @NumberOfRows
ORDER BY EmployeeID


which simply by changing @DesiredPageNumber, we can display data from different pages, but using OFFSET and FETCH in SQL-#Denali make it really simpler:

USE AdventureWorks
GO
DECLARE @NumberOfRows INT = 10 -- Number of rows you want on a page
DECLARE @DesiredPageNumber INT = 5 -- Page number

SELECT *
FROM HumanResources.Employee
ORDER BY EmployeeID
OFFSET (@NumberOfRows * (@DesiredPageNumber - 1)) ROWS
FETCH NEXT @NumberOfRows ROWS ONLY;
GO


as you can see it's really simpler and makes the developer's life much easier and has better has better Performance too.




reference

Saturday, April 23, 2011

OFFSET and FETCH on SQL Server Denali

The OFFSET and FETCH clause of SQL Server Denali provides you an option to fetch only a page or a window of the results from the complete result set.

look at some samples:

USE AdventureWorks2008R2;
GO
-- Return all rows sorted by the column DepartmentID.
SELECT DepartmentID, Name, GroupName
FROM HumanResources.Department
ORDER BY DepartmentID;

-- Skip the first 5 rows from the sorted result set and return all remaining rows.
SELECT DepartmentID, Name, GroupName
FROM HumanResources.Department
ORDER BY DepartmentID OFFSET 5 ROWS;

-- Skip 0 rows and return only the first 10 rows from the sorted result set.
SELECT DepartmentID, Name, GroupName
FROM HumanResources.Department
ORDER BY DepartmentID
OFFSET 0 ROWS
FETCH NEXT 10 ROWS ONLY;

Wednesday, April 13, 2011

SQL IntelliSense

Sometime I'm creating a new table or adding a column in SQL Server 2008, but when SELECTing from it I got the red squiggly line

the reason is :There are cases where the local cache used by IntelliSense becomes stale. Refreshing the cache is easy but not necessarily obvious.

There are two ways to refresh the cache:

1) Go to Edit -> IntelliSense -> Refresh Local Cache and
2) Hit Ctrl+Shift+R

Monday, April 11, 2011

Rounded Corners and Shadows – Dialogs with CSS

Great post about making 'Rounded Corners and Shadows' using CSS, do not miss it.

link

Tuesday, March 22, 2011

Microsoft SQL Server Migration Assistant

Microsoft SQL Server Migration Assistant (SSMA) is a toolkit that dramatically cuts the effort, cost, and risk of migrating from Access to SQL Server 2005, SQL Server 2008, SQL Server 2008 R2 and SQL Azure.

See writers blogs here and download it for:
Oracle
Access
MySQL

Sunday, March 20, 2011

EF 4.1

As you now last week Microsoft release new version of the EF(4.1), you can download it here.

Based on our experience we normally start to developing projects from designing and creating a database, but this way has some problems.

the biggest problem is that when we start to design classes and objects in the code part of project, our classes will be so similar to tables and we normally do not use great features of OO design like inheritance and ...
another issue is that there are many developers that don't have enough knowledge about database and database design rules like normalization so it's hard for them to design a database.

but new version of the EF(4.1) support Code-Base design. what does it mean? it mean that you can design your classes, your UI and all part of your application without even creating a table.you application will start to work, without any table,view,sp or any other issue related to database.

obviously, if you want to save your data you need to have a database, that's not a problem you can ask EF to do that for you ;-).

ScottGu's as always has great post about this issue, he redesign his NerdDinner application using this new EF ability, do not lose it.

Sunday, March 13, 2011

SQL Server Compact 4.0

Microsoft SQL Server Compact 4.0 is a free, embedded database that software developers can use for building ASP.NET websites ,Windows desktop applications and mobile devices.

Prior to the introduction of the desktop platform, it was known as SQL Server for Windows CE and SQL Server Mobile Edition. The latest release is the SQL Server Compact 4.0 supporting .NET Framework 4.0, and dropping support for Windows Mobile in this release.

You can download it from this address and its book online from this address.

Friday, March 11, 2011

Visual Studio LightSwitch

Tonight I watched some videos about Visual Studio LightSwitch,actual I have a very mixed sense about it.
from one point of view it is just an advance form maker, the better version or advanced version of Microsoft Access form maker that will not be so successful, I mean it remembers me the Microsoft Dynamic Data framework, that no body in the real world will use that.
but on the other hand, it has some cool features, it can connect to different data source(like SQL, SharePoint,...), you can simply create the data entry forms, report & search frorms and ... that are so useful for the people which are not professional software developer but like to write small application.

take a look on the Microsoft videos about this and say your views about it too me.

Monday, March 7, 2011

Accessing Server-Side Data from Client Script: Accessing JSON Data From an ASP.NET Page Using jQuery

Many times I was thinking about issues like: check the user-name availability before user click on Submit button, or master-detail Senario before post back.

this is a cool post by Scott Mitchell which wrote great ASP.NET Data-Access tutorial for ASP.NET site.

The current article is about Accessing Server-Side Data from Client Script using JSon and JQuesry. link

Sunday, March 6, 2011

WPF Developer Training Videos

I know Joe Stagner since 3-4 years ago, since he started to post some videos about ASP.NET.

he gather many cool videos about WPF and share link to them in his great web-log.

do not lose them ;-).

WPF Developer Training Videos

Wednesday, February 23, 2011

MVC Videos

As you know the MVC is great technology that Microsoft introduce around 2-3 years ago.
Although it's young technology but Microsoft is working hard on it and trying to established it as market developing standard.

ScottGu wrote a great post, and share some new videos about MVC:

MVC Videos

Tuesday, February 22, 2011

Step By Step Log-Shipping Configuration for SQL Server

it's really important to have good Disaster recovery plan.one way to prevanting a Database disaster(lose data) is using Log-Shipping, in below link you can find a good training stuffs about this great ability of SQL-Server:

link

Monday, February 21, 2011

Five Favorite Free SQL Server Downloads

this is great post about 5 different tools which can help us to find SQL-Server problems:


link

Thursday, February 17, 2011

Great JQuery Tree

you can find free JQuery Asp.Net tree in the below link:

JQuery Tree

Wednesday, February 16, 2011

Five DMV Queries That Will Make You a SQL Superhero

this is great post that will help you to find your SQL-Server bottleneck:

Click Here

Thursday, February 10, 2011

Assign Extension to application

There are two ways to assign extension to an application

1- on install time:
you can read about it on "The File Types Editor" part of below article:

How To Deploy .NET Windows Application

2- after running the application for a first time:

the below project is about this way

Code Project- Assign extension to a file


I prefer the first approach cause it's more standard

Wednesday, February 9, 2011

Getting Results the Agile Way

great post about how organise your life and work base of agile method:

The Agile Way

Tuesday, February 8, 2011

Useful, free resources for SQL Server

find a good list of SQL tools here:

SQL Server Free Resources