PDA

View Full Version : Esiste un comando per SQL Server2000 tipo, "CREATE TAB


race2
04-04-2002, 14:17
Con VB .NET + SQL Server2000, vorrei creare una tabella solo se non esiste gia', con MySql si usa il comando cha ho scritoto qui' sotto, come si fa per SQL Server2000 ???


Dim sql As String = "CREATE TABLE IF NOT EXISTS clienti(nome varchar(30))"

badaze
04-04-2002, 19:38
if (exists (select * from sysobjects
where name = '<table>' and type = 'U '))
drop table <table>

o qualcosa di simile...

race2
05-04-2002, 02:39
Originariamente inviato da badaze
[B]if (exists (select * from sysobjects
where name = '<table>' and type = 'U '))
drop table <table>

o qualcosa di simile...


Ho trovato:

-----------------------------------------------------------------------------------
Dim conn As New SqlConnection("Data Source=localhost;Initial Catalog=my_database;Integrated Security=SSPI;")


'crea la tabella clienti solo se non esiste
Dim sql As String = "if not exists (select * from dbo.sysobjects where xtype = 'U' and name = 'clienti') CREATE TABLE clienti (nome varchar(30)"


Dim Command As New SqlCommand(sql, conn)


Command.Connection.Open()
Command.ExecuteNonQuery()
Command.Connection.Close()