Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Help Groups for Snitz Forums 2000 Users
 Help: Database: MS SQL Server
 Changing Identity Insert Problem
 New Topic  Topic Locked
 Printer Friendly
Previous Page | Next Page
Author Previous Topic Topic Next Topic
Page: of 3

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 06 September 2005 :  07:57:22  Show Profile  Send ruirib a Yahoo! Message
quote:
Originally posted by Podge

One observation;

Its going to make for an ugly looking sp unless I can set my screen resolution to 5120x3840


Yeah, I agree with that . You can insert line breaks at the ';' though. It will still be ugly, but a little less ugly.


Snitz 3.4 Readme | Like the support? Support Snitz too

Edited by - ruirib on 06 September 2005 07:57:43
Go to Top of Page

Podge
Support Moderator

Ireland
3776 Posts

Posted - 06 September 2005 :  10:16:59  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
Actually, is there any need for the bit in red below?


<snipped>...FROM [' + @tablename + '].[dbo].[' + @tablename + '_AVATAR];SET IDENTITY_INSERT [snitzforum].[dbo].[' + @tablename +'_AVATAR] OFF')


Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 06 September 2005 :  12:55:17  Show Profile  Send ruirib a Yahoo! Message
Good question. I would say it's not, since our previous experience showed that it wasn't.

I do like to do things correctly, though. Call it a mania . I've seen too many times where we skip a detail and afterwards we add some change that does not work just because of the thing we forgot, or skipped.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Podge
Support Moderator

Ireland
3776 Posts

Posted - 07 September 2005 :  13:44:32  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
Just got around to testing this out and I would just like to say - You are the man!
Transferred a small forum in about a second. Much better than my previous dts solution. Will do some further testing and see how I get on.

Mania or not, thats a good attitude to have.

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 07 September 2005 :  15:01:04  Show Profile  Send ruirib a Yahoo! Message
Glad to know all worked ok .


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Podge
Support Moderator

Ireland
3776 Posts

Posted - 07 September 2005 :  18:53:52  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
Its working great so far. DTS used to fall over or hang after 3-5 databases. The sp keeps on going.

Next question....

I need to check if a column exists in a table in a database from within the same sp (from above) or another one in the same database. The columns I want to check will be in other databases than the sp.

I've defined the scalar function as described on this page

http://www.msde.biz/sqlfaq.htm

CREATE FUNCTION ColumnAlreadyExists(@TableName NVARCHAR(128),@ColumnName NVARCHAR(128))
RETURNS INTEGER--Returns 0 if column does not exist. Returns 1 if column exists.
AS
BEGIN
--See if the Table already contains the column.
IF EXISTS
(SELECT * FROM SysObjects O INNER JOIN SysColumns C ON O.ID=C.ID
WHERE ObjectProperty(O.ID,'IsUserTable')=1
AND O.Name=@TableName
AND C.Name=@ColumnName)
RETURN 1
--Table does not contain the column.
RETURN 0
END
GO

--Example of using SQL Server 2000 User Defined Scalar Function
--Drop then Add BT_FORMATTED column on the Temp_Hotspot table.
IF .dbo.ColumnAlreadyExists('Temp_Hotspot','BT_FORMATTED')=1
ALTER TABLE Temp_Hotspot DROP COLUMN BT_FORMATTED
ALTER TABLE Temp_Hotspot ADD BT_FORMATTED VARCHAR(500)

I can only check the column in the table in the database for which the function is defined. Is there a way to make this function available to all databases? Ideally I would like to be able to specify the database name as an argument if possible e.g.

IF .dbo.ColumnAlreadyExists('my_database', 'Temp_Hotspot','BT_FORMATTED')=1

Or is there an easier way to do what I want to do?

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 07 September 2005 :  20:51:43  Show Profile  Send ruirib a Yahoo! Message
I guess you could use the usual [database].[owner].SysObjects syntax. A quick test showed this syntax to work.

However, it's not possible, AFAIK, to use this syntax in a system defined function (nor in UDF), that could accept the database name as a variable, since that would mean you'd need to insert the 'SELECT * From [@dbname].[owner].SysObjects O...' in an EXEC command, and EXEC commands cannot be used inside UDFs (nor inside SDFs, obviously).

This means you can have a function in a database that checks the existence of a column in another database, with the other database name 'hardcoded', but not a single function that would dothe checking for all databases.


Snitz 3.4 Readme | Like the support? Support Snitz too

Edited by - ruirib on 07 September 2005 20:52:38
Go to Top of Page

Podge
Support Moderator

Ireland
3776 Posts

Posted - 08 September 2005 :  07:42:19  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
Thought as much. I can do it programatically using this http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthopenschema.asp

It seems the simplest way.

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page

AnonJr
Moderator

United States
5768 Posts

Posted - 08 September 2005 :  08:41:05  Show Profile  Visit AnonJr's Homepage
Not to intrude, as I've not had a chance to work with sp's yet, but you might be able to do what you want using ADOX (ADO Extensions) and VBScript. I can't seem to find the link right now, but for my Online Testing program I use ADOX to check if the log table for a test exsists - and write it if it doesn't - since this is not done when a new test is added.

I don't know if this works for non-ms databases though...
Go to Top of Page

AnonJr
Moderator

United States
5768 Posts

Posted - 08 September 2005 :  08:50:25  Show Profile  Visit AnonJr's Homepage
Found a couple of ADOX resources you could use if you are interested in going down that road:

MSDN ADOX Reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/admscadoapireference.asp

http://www.asp101.com/articles/wrox/asp30/26100904.asp

http://www.4guysfromrolla.com/webtech/013101-1.shtml

(ADOX is a part of ADO 2.1+)
Go to Top of Page

Podge
Support Moderator

Ireland
3776 Posts

Posted - 08 September 2005 :  09:52:45  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
I might be able to do it from within the stored procedure if I do it like this (not tested).

exec ('use ' + @mydatabase + '; if exists (select * from information_schema.columns where table_name = '' + @mytable + '' and column_name = '' + mycolumn +'') print ''column exists'' else alter mytable add whatever int 0'; use master)


And now in readable form;

use MyDatabase
GO
if exists (select * from information_schema.columns
where table_name = 'OGRISH'
and column_name = 'ALEB')
-- build some dynamic query
else
-- build another dynamic query
use myOtherDatabase
GO

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.

Edited by - Podge on 08 September 2005 09:53:55
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 08 September 2005 :  11:23:12  Show Profile  Send ruirib a Yahoo! Message
Yeah, no problem doing that, I'd say.

You could also use an exec with the [@DB].[@owner].[@table] syntax, but I think that previous option is less cryptic.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Podge
Support Moderator

Ireland
3776 Posts

Posted - 08 September 2005 :  18:01:05  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
It works. This is the line with correct syntax.


exec ('use my_forums; if exists (select * from information_schema.columns where table_name = ''FORUM_A_REPLY'' and column_name = ''CAT_ID'') print ''column exists'' else print''does not exist''; use master')

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 08 September 2005 :  18:10:46  Show Profile  Send ruirib a Yahoo! Message
Good .


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Podge
Support Moderator

Ireland
3776 Posts

Posted - 08 September 2005 :  18:26:40  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
Just wondering what you think of the ability of using dotnet programming languages in sp's in SQL 2005 e.g. http://www.sqlservercentral.com/columnists/aAnajwala/simplesqlclrintegration.asp

I know it would have helped me a lot with my current little project but I have mixed feelings about it. On one hand I think it has benefits but on the other hand should the majority of the programming not be in a middle tier (or elsewhere) and not in the database layer?

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page
Page: of 3 Previous Topic Topic Next Topic  
Previous Page | Next Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.22 seconds. Powered By: Snitz Forums 2000 Version 3.4.07