Posts

Showing posts from April, 2012

Split Datetime to seperate fields as date and time

SELECT CONVERT(varchar, GETDATE(), 101) as Date SELECT CONVERT(varchar, GETDATE(), 108) as Time You can give your own datetime fields instead of GETDATE().

Procedure that finds a specific data in all tables of a database

ALTER PROC [dbo].[SearchAllTables] ( @SearchStr nvarchar(100) ) AS BEGIN -- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved. -- Purpose: To search all columns of all tables for a given search string -- Written by: Narayana Vyas Kondreddi -- Site: http://vyaskn.tripod.com -- Tested on: SQL Server 7.0, SQL Server 2000, SQL server 2005 -- Date modified: 28th July 2002 22:50 GMT CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630)) SET NOCOUNT ON DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110) SET  @TableName = '' SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''') WHILE @TableName IS NOT NULL BEGIN SET @ColumnName = '' SET @TableName = ( SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND QUOTENAME...

Database Diagram Error

ERROR=" Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects. " SOLUTION In SQL Server Management Studio do the following: 1. Right Click on your database, go to properties 2. Goto the Options  3. In the Dropdown at right hand "Compatibility Level" choose "SQL Server 2005(90)" 4. Goto the Files  5. Enter "sa" in the owner textbox. 6. click OK Now you will be able to create a database diagram.