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’
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)
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 [...]
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
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 [...]
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 [...]
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 [...]
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 [...]
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 [...]
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 [...]