用SQL语句如何生成一个新的数据表???

我要在网页中用SQL语句生成一数据表
所在数据库:Mydatabase
数据表名:Mytable
字段:
name--->nvarchar
ID ---->int

先确认是否数据库中已经存在同名的数据表,如存在则不建立。
---------------------------------------------------------------

数据库在你连接的时候可以确定

if not exist(select name from sysobjects where name='Mytable')
begin
create table Mytable..................
end
---------------------------------------------------------------

先确认是否数据库中已经存在同名的数据表,如存在则不建立:

if not exists(select name from sysobjects where name='Mytable')
begin
create table Mytable
'(
ID int identity(1,1) Not null,
name nvarchar(50) null

)'
end
else
不建立
---------------------------------------------------------------

sql="if not exist(select name from sysobjects where name='" & Mytable & "')\nbegin\ncreate table " & Mytable & "(ID int identity(1,1) Not null,name nvarchar(50) null)\nend"
执行之
---------------------------------------------------------------

 1   
 2set con = server.createobject("ADODB.connection")   
 3con.open "Driver={SQL SERVER};SERVER=DZEDA;uid=***;pwd=***;database=test"   
 4sql="select name from sysobjects where name='Mytable'"   
 5set rs = server.createobject("ADODB.recordset")   
 6rs.open sql,con,1,1   
 7if rs.eof and rs.bof then   
 8sql="create table Mytable(ID int identity(1,1) Not null,name nvarchar(50) null)"   
 9con.execute(sql)   
10end if   
11rs.close   
Published At
Categories with Web编程
comments powered by Disqus