判断SQL数据库是否存在表,是否存在记录
来源:互联网 发布:linux基础知识总结 编辑:程序博客网 时间:2024/04/30 15:13
SQL数据库,当判断一条记录存在时,则更新更记录,当记录不存在时,则添加该记录
使用SQL语句在C#中实现,sql语句
if exists
(select * from 表 where 条件)
begin
Update 表 Set 字段=字段值 where 条件
end
else
begin
Insert into dbo.表名(字段) values
(字段值)
end
比如:
if exists
(select * from CollectRain_201404 where StationId='D6021' and CollectTime='20140406232000')
begin
Update CollectRain_201404 Set CollectRainFall='22222',IsValue='false' where StationId='D6021' and CollectTime='20140406232000'
end
else
begin
Insert into dbo.CollectRain_201404 (StationId,CollectTime,CollectRainFall,IsValue) values
('D6021','20140406232000','11111','true')
end
当判断一个表是否存在数据库时,当数据库不存在该表时,则需要新建该表
使用SQL在C# NET中实现方法
if exists
(select * from sysobjects where id = object_id(N'[表名]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
print 'f'
else
begin
CREATE TABLE 表名
(
建表
)
end
比如
if exists
(select * from sysobjects where id = object_id(N'[Test]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
print 'f'
else
begin
CREATE TABLE Test
(
Id int IDENTITY(1,1) PRIMARY KEY,
StationId nvarchar(MAX) NOT NULL,
CollectTime nvarchar(MAX) not null,
CollectRainFall float not null,
IsValue bit not null
)
end
- 判断SQL数据库是否存在表,是否存在记录
- 用SQL语句判断数据库中的记录是否存在
- 判断数据库表是否存在
- sql判断是否存在
- SQL判断是否存在
- 判断数据库是否存在
- 判断数据库是否存在
- SQL语句判断记录是否存在
- sql检测表是否存在,列是否存在,判断类型
- sql 判断数据库是否已存在
- SQL Server中判断数据库是否存在
- sql server如何判断数据库是否存在
- 判断表中是否存在记录的SQL语句
- SQL 判断表中是否存在记录的高效率方法
- Sql Server中判断表或者数据库是否存在
- Sql Server中判断表或者数据库是否存在
- SQL语句判断表 数据库 数据是否存在
- Sql Server中判断表或者数据库是否存在
- js 数字转大写汉字
- 三星手机丢失了数据怎么找回
- 编程规范---如何写出无法维护的代码
- android中Http访问时 connection.getResponseCode()不被执行
- java读取http请求中的body
- 判断SQL数据库是否存在表,是否存在记录
- Java生成二维码
- opencv载入图片,并得到行列值
- Magento 常用技巧与方法
- git恢复删除的分支
- MySQL 模拟条件索引
- SVN不能读取日志
- Phoenix实战(hadoop2、hbase0.96)
- 测试环境redis数据库的使用