如何避免在SQL中破坏语句 [英] how to avoid breaking of statement in sql

查看:73
本文介绍了如何避免在SQL中破坏语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询正在创建4个表.但是在数据库中,第一个表已经存在,而其他表已经不存在.当创建第一个表时,由于表的存在,它显示为对象已经存在并且脱离查询.但是我想创建其余的表.如何避免查询中断.请帮帮我


谢谢你

解决方案

检查表是否存在,并仅在不存在时创建.

 如果  存在(选择 * 来自 dbo.sysobjects 其中 id = object_id(N '  [dbo].[table1]') 对象属性(id,N '  1 )
开始
  创建  ...
 END  


嗨....

请尝试以下查询.

 如果 object_id(' 销售" ) 不是 为空
创建 销售
(
sno  int ,

名称 varchar ( 20 )
)




选择数据库

检查此条件表是否存在

(从sys.objects中选择*,其中object_id = object_id(''[dbo].[n_table]''))

然后

创建表


i have a query which is creating 4 tables.but in the database the first table is already exists not the further tables. when it comes to creation of first table,as the table exixts it is displaying as object already exists and coming out of query. but i want to create the rest of the tables.how can i avoid the breaking of query. Please help me


Thank You

解决方案

Check to see if the table exists and only create if it does not.

if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[table1]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE ...
END


Hi ....

Please try the below query.

If object_id('sales') is not null
create table sales
(
sno int,

name varchar(20)
)


hi,

select the database

check this condition the table exists or not

(select * from sys.objects where object_id = object_id(''[dbo].[n_table]'')

then

create table


这篇关于如何避免在SQL中破坏语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆