SQL Server 2008

SQL Server
T-SQL Questions and Examples
Lessons Deserved to Be Recorded and Studied

How to Get SQL Table Field Structure?

2017/05/15
By
Modified: 2017/04/30
SQL-2008-R2

Sometimes you need to display or print a SQL table structure. This article provides a SQL statement that allows you to do that. We are using MS SQL 2008 Studio interface.

Read more »


The EXECUTE permission was denied on the object ‘aspnet_CheckSchemaVersion’, database ‘YourDB’, schema ‘dbo’

2017/05/09
By
Modified: 2017/04/30

ASP.NET page returns this erorr: The EXECUTE permission was denied on the object ‘aspnet_CheckSchemaVersion’, database ‘YourDB’, schema ‘dbo’. (1) First try runing this command/wizard: %WinDir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe   (2) If this doesn’t work, try this query:  -- Add user ASPNET to DB role USE YourDB GO sp_addrolemember 'aspnet_Membership_FullAccess', 'ASPNET' These steps should resolve your issue.

Read more »

Add a FILESTREAM feature to an existing SQL D/B

2017/05/07
By
Modified: 2017/04/30
SQL 2008 SP2 FILESTREAM Problem

SQL Server 2008 allows to store binary data, if Database has a FILESTREAM feature

Read more »

Moving Old ASP Sites to 2008 Server, IIS 7, and SQL 2008

2017/04/13
By
Modified: 2017/03/03
Moving Old ASP Sites to 2008 Server, IIS 7, and SQL 2008

It was time to move many sites from W2K3 Server (Windows 2003 Server) and SQL 2000 Server to a new W2K8 Server (Windows 2008 Server) and SQL 2008 Server.  And if I ever have to do it again, I will check with these notes. The greatest secret in technical life (and may be wider) is to change before you have to.  Anticipate and change before circumstances force you.  For a long time I was planning this migration, but I didn’t expect to go through so many hurdles and error messages.  Luckily, I found solutions that seem logical and clean.  So, let’s go into step-by-step details. COPY DATABASE AND SITES – Backup…

Read more »

How to Compare SQL SmallDateTime Fields for Equality

2017/04/01
By
Modified: 2017/03/03
MS SQL Server 2008 R2

It is meaningless to compare for equality (==) two fields of type SmallDateTime, because they contain time component and they are hardly ever the same. Here are some interesting ways around this problem to check, if two SmallDateTime fields have the same date component.

Read more »

Allow to Pass Optional Parameters to a Stored Procedure

2017/03/28
By
Modified: 2017/03/03
Mount Carrigain NH 1427m

This article shows how to use string parameters to make selection on Boolean fields. What is it you need to select "true", "false" of "ALL" records. How WHERE statement will look like in that case?

Read more »

SQL – Count combinations of values in several columns

2017/03/24
By
Modified: 2017/03/23
Life is a Passage

You have a large table (in my case it has 8,697,647 records) with an Asset Number and a Business Unit, and you would like to know if any asset has record with multiple Business Units. You can count records of unique Asset/BU combinations, but this is not what you want: SELECT FLNUMB, FLMCU, COUNT(FLAID) AS COUNT FROM JDE_CRP.CRPDTA.F1202 GROUP BY FLNUMB, FLMCU ORDER BY FLNUMB, FLMCU This query will return results similar to these: FLNUMB FLMCU COUNT 84865 12000 66 84866 12000 66 84867 12000 75 84867 12704 18 84867 12705 28 84868 12000 75 84868 12715 22 84868 12717 32 84869 12000 66 84870 12000 75 84870 12535 40 84871…

Read more »

How to Re-Install SQL Server 2008 Evaluation

2017/03/20
By
Modified: 2017/03/03

You have 180 days to evaluate.  You can check number of days till expiration:   open your SQL Server Management Studio and widen first line in Help — About box. What if your trial is about to expire, and you need just a few more days to evaluate? You can switch to a free Express edition, or you can follow this cumbersome procedure.   =01= Un-Install SQL Server 2008 Drop all your custom databases Run your Maintenance Plan one last time Save all your maintenance plans (this step was not tested) Go to Control Panel – Programs and Features Uninstall Microsoft SQL Server 2008 – Remove Check Rules – Next Select Features –…

Read more »

Fix “Cannot generate SSPI context” while connecting to SQL Server

2017/03/14
By
Modified: 2017/03/14
SQL - Cannot generate SSPI context

Here is a problem resolved here – you can connect to MS SQL Server 2012 from the office, but when your try to connect from home over remote (in this case AVENTAIL) connection you would get an error message: “Cannot generate SSPI context“. Once again, from the office you can connect to several SQL servers of different versions from 2008 to 2012 using SQL Server Management Studio (SSMS), but remotely one of the servers gives you the error about SSPI Context.  You are using Windows Authentication to connect. Google search will reveal that error has something to do with domain user name not being properly recognized or registered on the server…

Read more »

SQL Error 80004005 – “Specified SQL server not found” – Solved

2017/03/08
By
Modified: 2017/03/03
SQL CFG Manager - Enable TCPIP

  Environment ASP or ASP.NET site is running on IIS 7.5. SQL Server 2008 R2 Express (10.50.1600.1) running on Windows 2008 Server R2 (W2K8 R2) x64.     Problem You will see one of two errors depending on whether you dealing with ASP or ASP.NET sites. On ASP.NET sites you will see  “Server Error – Error: 26 – Error Locating Server/Instance Specified” Server Error in '/YourApps' Application. A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26…

Read more »

Automate Database Backup with SQL Express

2017/03/02
By
Modified: 2017/02/22
Automate Database Backup with SQL Express

This article describes, how to automate database backup in SQL Express with mixed Windows and SQL Authentication running on Windows 2008 Server.   This material was tested with Microsoft SQL Server 2008 R2 Express. SQL Server 2008 Enterprise comes with Maintenance Plan feature.  That feature allows amazing flexibility and auditing.  SQL Express edition lacks this feature.  But you still need a backup. Backup automation with SQL Express consist of 3 steps: (1) Write the script to backup all your databases. (2) Test the script by initiating it from a command prompt. (3) Schedule the script using Task Scheduler. Here is each step in detail. ` (1) Write the Script This script overwrites…

Read more »