数据库 sql server
if exists(select * from sys.objects where name='test')
drop table test
go
create table test
(
id varchar(),
name varchar()
)
if exists(select * from sys.objects where name='t_insert')
drop trigger t_insert
go
create trigger t_insert on test
instead of insert
as
declare @id varchar(),@id1 int,@head varchar()
select * into #tb from inserted
set @head='uzi'+convert(varchar(),getdate(),)
select @id=max(id) from test
--if @id is null
--set @id1=
--else
--set @id1=cast(substring(@id,,) as int)
if exists(select * from test)
set @id1=cast(substring(@id,,) as int)
else
set @id1=
update #tb set @id1=@id1+,id=@head+right(''+cast(@id1 as varchar),)
insert into test select * from #tb
go
insert into test(name) values('小马')
insert into test(name) values('小明')
insert into test(name) values('小鱼') select * from test
表test
if exists(select * from test)
select '0' -------------------------------------------------
else -- 表中有数据时为: 0 | 表中无数据时为: 1 --
select '1' -------------------------------------------------
if exists(select count(*) from test)
select '0' --------------------------------------------------
else -- 表中有数据时为: 1 | 表中无数据时为: 0 --
select '1' --------------------------------------------------
丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄丄
【判断表中是否有数据】
丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅丅
--使用局部变量
--select @id=max(id) from test
--if @id is null
--set @id1=0
--else
--set @id1=cast(substring(@id,12,4) as int)
2、一样的代码,就差一个范围,效果不相同
if exists(select * from sys.objects where name='test')
drop table test
go
create table test
(
id varchar(),
name varchar()
)
if exists(select * from sys.objects where name='t_insert')
drop trigger t_insert
go
create trigger t_insert on test
instead of insert
as
declare @id varchar(),@id1 int,@head varchar()
select * into #tb from inserted
set @head='uzi'+convert(varchar(),getdate(),)
select @id=max(id) from test
if @id is null
set @id1=
else
set @id1=cast(substring(@id,,) as int)
update #tb set @id1=@id1+,id=@head+right(''+cast(@id1 as varchar),)
insert into test select * from #tb
go
insert into test(name) values('小马')
insert into test(name) values('小明')
insert into test(name) values('小鱼') select * from test
if exists(select * from sys.objects where name='test')
drop table test
go
create table test
(
id varchar(),
name varchar()
)
--触发器
if exists(select * from sys.objects where name='t_insert')
drop trigger t_insert
go
create trigger t_insert on test
instead of insert
as
declare @id varchar,@id1 int,@head varchar()
select * into #tb from inserted
set @head=convert(varchar(),getdate(),)
select @id=max(id) from test
if @id is null
set @id1=
else
set @id1=cast(substring(@id,,) as int)
update #tb set @id1=@id1+,id=@head+right(''+cast(@id1 as varchar),)
insert into test select * from #tb
go
insert into test(name) values('小马')
insert into test(name) values('小白')
insert into test(name) values('小黑')
select * from test
给变量添加类型后规定范围(第2个16行代码处)
(a)declare @id varchar,@x int,@head varchar(20)
效果为:
201606140001 小黄
201606140001 小白
201606140001 小黑
(b)declare @id varchar(20),@x int,@head varchar(20)
效果为:
201606140001 小黄
201606140002 小白
201606140003 小黑
(c)declare @id varchar(20),@x int,@head varchar
效果为:
20001 小黄
20001 小白
20001 小黑
数据库 sql server的更多相关文章
- 数据库SQL Server与C#中数据类型的对应关系
ylbtech- .NET-Basic:数据库SQL Server与C#中数据类型的对应关系 数据库SQL SServer与C#中数据类型的对应关系 1.A,返回顶部 数据库 C#程序 int int ...
- 数据库管理工具神器-DataGrip,可同时管理多个主流数据库[SQL Server,MySQL,Oracle等]连接
前言 DataGrip:Jet Brains出品的一款数据库管理工具(没错,是Jet Brains出品,必属精品).DataGrip整合集成了当前主流数据库(如:SQL Server, MySQL, ...
- sql server ------创建本地数据库 SQL Server 排序规则
sql server完整复制数据库 sql server导入导出方法 SQL Server 排序规则
- 数据库 SQL Server 到 MySQL 迁移方法总结
最近接手一起老项目数据库 SQL Server 到 MySQL 的迁移.因此迁移前进行了一些调查和总结.下面是一些 SQL Server 到 MySQL 的迁移方法. 1. 使用 SQLyog 迁移 ...
- [数据库]SQL Server 用户NT AUTHORITY\IUSR 登录失败
今天打开网站时,突然报这个错误,平时都好好的 Cannot open database "JMECC" requested by the login. The login fail ...
- 数据库SQL Server DAC 导入导出数据到SQL Azure问题
对Export data-tier application报错的处理 Error:SQL71564 这个问题是数据库中一些对象如MS_Description,MS_DiagramPane1不支持DAC ...
- 如何分离数据库 (SQL Server Management Studio)
在 SQL Server Management Studio 对象资源管理器中,连接到 SQL Server 数据库引擎的实例上,再展开该实例. 展开“数据库”,并选择要分离的用户数据库的名称. 分离 ...
- 批量还原数据库 SQL Server 2008
1.如果你够懒,不想一步一步点路径,一步一步选择 2.如果你连单个备份数据库的存储过程都不想多执行,一般每还原一个需要修改数据库名 下面的脚本适合你: /*********************** ...
- 基础知识(C#语法、数据库SQL Server)回顾与总结
前言 已经有大概一个多月没有更新博客,可能是开始变得有点懒散了吧,有时候想写,但是又需要额外投入更多的时间去学习,感觉精力完全不够用啊,所以为了弥补这一个多月的潜水,决定写一篇,衔接9月未写博客的空缺 ...
- 数据库 --> SQL Server 和 Oracle 以及 MySQL 区别
SQL Server 和 Oracle 以及 MySQL 区别 三者是目前市场占有率最高(依安装量而非收入)的关系数据库,而且很有代表性.排行第四的DB2(属IBM公司),与Oracle的定位和架构非 ...
随机推荐
- 原生JavaScript技巧
时常在技术论坛有看见一些比较好的示例,于是就出于一种收集并学习的态度,于是就保留下来啦~ 当然现在展示的也只是一部分,先放一部分出来尝尝鲜~~~
- Spring中集合类型属性注入
我们都知道如何去注入普通属性的值,非常简单,那么我们如何去注入开发中常见的集合类型的属性了,别急,往下看. 这里将介绍如何给Map list set Array Properties 这些属性注入值. ...
- C和指针 第五章 习题
下列输出的值: #include <stdio.h> int func(){ static int count = 1; return ++count; } int main() { in ...
- ngCloak 实现 Angular 初始化闪烁最佳实践
在做angular的SPA开发时,我们经常会遇见在如Chrome这类能够快速解析的浏览器上出现表达式({{ express }} ),或者是模块(div)的闪烁.对于这个问题由于JavaScript去 ...
- ecshop二次开发常用文件位置
语言包修改: /language/zh_cn/admin/common.php 商品详情页模板: /themes/**/goods.dwt (最下方有changePrice() 点选属性或改变数量时 ...
- RobotFrameWork(四)变量运算与Evaluate
一.特殊变量运算: 执行结果: 二.Evaluate使用 函数释义:Evaluate是执行Python表达式,并返回执行结果 示例1: 执行结果: 示例2: 执行结果:
- mongoTemplate简单用法(增删改查)
分页时查找数量: public long countSample(String id) { Query query = new Query(); if (StringUtil.hasText(id)) ...
- C# 使用SqlBulkCopy类批量复制大数据
用途说明: 前些日子,公司要求做一个数据导入程序,要求将Excel数据,大批量的导入到数据库中,尽量少的访问数据库,高性能的对数据库进行存储.于是在网上进行查找,发现了一个比较好的解决方案,就是采用S ...
- 移动端touchstart、touchmove事件的基本使用
在pc端,我们通常使用$(window).scroll()事件来监听元素的位置,来做一些入场动效,如: $(window).scroll(function(){ var panel3Move = do ...
- 【转载】PyQt QSetting保存设置
转载地址: http://blog.sina.com.cn/s/blog_4b5039210100h3zb.html 用户对应用程序经常有这样的要求:要求它能记住它的settings,比如窗口大小,位 ...