Sponsored Links

How to get the name and definition of all Stored Procedures in a Database?

Today I wanted to get the script of all the Stored procedures in a database. I used this query to do so. Pretty much self explanatory is this, isn’t it?

Use [myDatabaseName]

SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE=’PROCEDURE’

how to convert an integer to string and left pad it with zero's?

Here’s a quick and simple way of converting an integer to string (varchar) and left pad it with leading zeros like 00012. This example will get the result in 5 digits

select right(‘00000′ + cast(yourfield as varchar(5)), 5)

How to make a case sensitive comparision of strings in SQL Server

String in SQL Server are by default case insensitive. That means that “SQL” is equivalent to “sql” and it causes problems when you’re making a password authentication mechanism which is supposed to be case senstive. Here’s an example stored procedure in which I’m making a case sensitive string comparison for the password field using Collations.

CREATE [...]

How to change the ownership of a database

You can change the ownership of a database with this statement. It cured another problem that I got, I dont remember the exact statement

sp_changedbowner  @loginame =  ’sa’ ,  @map= false

How to determine effective permission of an SQL Server 2005 object?

You can find out the effective permissions on an SQL Server 2005 object by using a function called fn_my_permissions. Here’s what’s written in the books online.

fn_my_permissions 

Returns a list of the permissions effectively granted to the principal on a securable.

Syntax
fn_my_permissions ( securable , ’securable_class’)
Arguments

securable
Is the name of the securable. If the securable is the server [...]

How to reseed the identity value of a table?

I was working on a project and there was a lookup table in that which needed to be populated and its identity values needed to strictly match with the database at my client’s end. At first when I tried to insert data from another table it turned in to an error, the rows didnt get [...]

How to access data from two different tables in SQL Server 2005?

howdy,

well I was having a problem where I needed to populate the table of my SQL Express 2005 database from another table in another database. So I wrote the query in the following fashion:

INSERT INTO debtdb.SchemaName.TableName (column1, column2….)

SELECT Column1, column2…

FROM dbName.SchemaName.TableName

 

my sample query was this

Insert into db2.dbo.tblNationality(NationalityName) 

Select

Name FROM db1.dbo.tblNationality

what it does is that it [...]

Changing a Column to Identity after creation.

Today I had to change the Primary key columns in tables so that they can become identity columns but I couldn’t do it using Alter Table x Alter column y IDENTITY(1,1) command. So I found out that you can’t use ALTER TABLE to change a column into IDENTITY column (except on SQL Server CE!). One [...]

Generating an XML Schema of SQL Server 2005 Database

I was told to generate an XML Schema of an SQL Server 2005 Database. And naturally I started googling it out so I found this at a blog given by the URL at the bottom.

Thumbs up to ya my friend!

create table Person
(
Age int not NULL check( Age > 0) ,
Height numeric(10,2) not NULL check( Height [...]

Custom Paging in ASP .NET using SQL Server 2005

Download the code

Hello everyone,

Here I’m going to explain how I managed to implement Custom Paging in my project. It involved an extensive amount of data that was used for searching and I definitely needed a better option than the default paging. In a nutshell, Default paging gets the complete set of records although it needs [...]