Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   if exists table then (https://www.delphipraxis.net/152485-if-exists-table-then.html)

arcon 24. Jun 2010 08:32

Datenbank: MS SQL • Version: 2005 • Zugriff über: Inat OPC , Ethernet

if exists table then
 
hallo miteinander,

ich verzweifel langsam. ich möchte einfach nur überprüfen, ob eine tabelle vorhanden ist .. mehr soll erstmal nicht passieren .. ( im fortgeschrittenen stadium soll dann die tabelle gelöscht werden .. aber erstmal muss die prüfung korrekt funktionieren !)

und zwar benutze ich in einer query-abfrage folgenden sql-code

SQL-Code:
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE (name = 'testversion'))

else
END
aber das will einfach nicht funktionieren.
als fehlermeldung erscheint ...

Incorrect syntax near the keyword 'else'.

was mach ich falsch ? die anderen im i-net haben es doch auch so gelöst .. ich werde bald verrückt ..

danke für eure bemühungen

arcon 24. Jun 2010 08:57

AW: if exists table then
 
Problemlösung:

SQL-Code:
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[DEINE_TABELLE]') )
  DROP TABLE [dbo].[DEINE_TABELLE]
DEINE_TABELLE musst du nur abändern .. und es wird funktionieren ...

sniper_w 28. Jun 2010 09:37

AW: if exists table then
 
T-SQL erlaubt kein leeres Codeblock.
SQL-Code:
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE (name = 'testversion'))
BEGIN
  declare @dummy1 int;
END
ELSE
BEGIN
  declare @dummy2 int;
END


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:40 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz