Re: how to check if mytable is exist via an asp file



Hi!

I suggest you to use a stored procedure like this:

CREATE PROCEDURE proc_CreateTable
(
@TableToCreate nvarchar(30)
)
AS
BEGIN

SET NOCOUNT ON;

DECLARE @SQLTable nvarchar(1000)

-- create drop table script
SET @SQLTable = 'DROP TABLE ' + @TableToCreate

-- check if the table exists. In that case, drop table with
sp_executeSQL
IF EXISTS (SELECT * FROM sys.objects WHERE object_id =
OBJECT_ID(@TableToCreate) AND type in (N'U'))
EXEC sp_ExecuteSQL @SQLTable

-- create script for create table
SET @SQLTable = 'CREATE TABLE ' + @TableToCreate + '
(
id int identity(1,1) primary key clustered,
description varchar(100)
)'

-- execute the create table script
EXEC sp_ExecuteSQL @SQLTable
END

It is valid for SQL Server 2000 and 2005. You can improve this script
adding a schema/owner check. In sql server 2005 you can check it into a
system view called sys.schemas.

All that you have to do in asp it's to create an ado command and
execute it as a Storedprocedure command, adding also a parameter called
@TableToCreate into parameters collection of command object.

That's all..
hope this help..
bye!

Mint wrote:
i want to create an asp script.
it can do the task below.
1. check if the mytable is exist?
2. if exists drop mytable
3. create my mytable.
my question how to check if mytable is exist?
please advice an asp script.
or anyone can tell me how to create a procedure which can create a
table , the table will be a paremeter , and i can run call the
procedure in an asp file.
many thanks.

.



Relevant Pages

  • Re: composite key question
    ... Each time you do an insert SQL ... it's probably not a stored procedure. ... queries to perform slower, however. ... Seeing as how that script you sent was not a stored proc, ...
    (microsoft.public.sqlserver.programming)
  • source text file as input parameter from a stored procedure
    ... I am using an active X script in combination with a global ... transform task that loads data from a .txt file to a table. ... I can also tell that the stored procedure is correctly passing in the ... EXEC sp_OAGeterrorinfo @object, @hr ...
    (microsoft.public.sqlserver.dts)
  • RE: Error 207 doing Transactional replication via Internet
    ... stored procedure from the script we were running. ... Some of them you didn't want to move to the subscriber so you ... For the QQRMGR user you ...
    (microsoft.public.sqlserver.replication)
  • Re: What does the .run method return
    ... 'stored procedure', yet your example is a VBS script. ... I have a batch job that calls a VBscript. ...
    (microsoft.public.scripting.vbscript)
  • Re: Newbie - Stored Procedures/ASP Question
    ... I tried shortening the Stored Procedure, and using the script from your ... The SQL Stored Procedure is below. ...
    (microsoft.public.inetserver.asp.db)