sql server 删除所有表和递归查询、数字类型转为字符串
1、删除所有表
DECLARE c1 cursor for
select 'alter table ['+ object_name(parent_obj) + '] drop constraint ['+name+']; '
from sysobjects
where xtype = 'F'
open c1
declare @c1 varchar(8000)
fetch next from c1 into @c1
while(@@fetch_status=0)
begin
exec(@c1)
fetch next from c1 into @c1
end
close c1
deallocate c1 declare @sql varchar(8000)
while (select count(*) from sysobjects where type='U')>0
begin
SELECT @sql='drop table ' + name
FROM sysobjects
WHERE (type = 'U')
ORDER BY 'drop table ' + name
exec(@sql)
end
2、删除所有存储过程
declare @tname varchar(8000)
set @tname=''
select @tname=@tname + Name + ',' from sysobjects where xtype='P'
select @tname='drop proc ' + left(@tname,len(@tname)-1)
exec(@tname)
go
3、删除所有视图
declare @tname varchar(8000)
set @tname=''
select @tname=@tname + Name + ',' from sysobjects where xtype='V'
select @tname='drop view ' + left(@tname,len(@tname)-1)
exec(@tname)
go
4、递归查询 使用关键字with as
with temp ( [Id], [parentid])
as
(
select Id, ParentId
from SysLocation
where ParentId = @ParentId
union all
select a.Id, a.ParentId
from SysLocation a
inner join temp on a.ParentId = temp.[Id]
) select s.Id, s.ParentId from SysLocation s where Id=@ParentId
union all
select * from temp
5、数字类型转为字符串
select convert(varchar(11),convert(decimal(11,0),mo)) as m from test
6、创建外键
alter table ResolvedOrderNew
add constraint FK_ResolvedOrderNew_QuotaOrderNew
foreign key (QuoteOrderNewId) references QuoteOrderNew(Id);
sql server 删除所有表和递归查询、数字类型转为字符串的更多相关文章
- Sql Server删除数据表中重复记录 三种方法
本文介绍了Sql Server数据库中删除数据表中重复记录的方法. [项目]数据库中users表,包含u_name,u_pwd两个字段,其中u_name存在重复项,现在要实现把重复的项删除![分析]1 ...
- Sql Server 删除所有表
如果由于外键约束删除table失败,则先删除所有约束: --/第1步**********删除所有表的外键约束*************************/ DECLARE c1 cursor f ...
- sql server 删除所有表、视图、存储过程
如果由于外键约束删除table失败,则先删除所有约束: --/第1步**********删除所有表的外键约束*************************/ DECLARE c1 curs ...
- Sql Server 删除所有表 脚本
如果由于外键约束删除table失败,则先删除所有约束: --/第1步**********删除所有表的外键约束*************************/ DECLARE c1 cursor f ...
- sql server 删除所有表和存储过程
1.删除外键约束 DECLARE c1 cursor for select 'alter table ['+ object_name(parent_obj) + '] drop constraint ...
- Sql Server 删除所有表(转)
http://www.cnblogs.com/jys509/p/3589468.html 首先必须要清空所有表的外键 DECLARE c1 cursor for select 'alter tabl ...
- SQL Server删除表信息的三种方法
1.使用DELETE实现SQL Server删除表信息 (1)删除表中的全部信息 USE student GO DELETE student --不加where条件,删除表中的所有记录 go ...
- SQL server 数据库用户表名称
转自(http://blog.163.com/jlj_sk/blog/static/22579293200861422833924/) 取得SQL server 数据库中 所有用户表名称 select ...
- SQL Server数据库、表、数据类型基本概念
一.SQL Server的数据存储结构 SQL Server是一个数据库管理系统,需要以有效方式存储高容量数据.要更好地理解SQL Server处理数据的方式,就需要了解数据的存储结构. 1.文件类型 ...
随机推荐
- Java第二次作业程序设计作业
本次作业包含两个部分:一是以下4个题目的程序源码和运行结果截图:二是本次作业的小结(谈谈你在做作业的过程中遇到了哪些问题,如何解决,有哪些收获). 1.编写"人"类及其测试类. 1 ...
- 毕业设计5:基于MicroPython的智能火灾报警器系统的设计与实现
随着现代家庭用火.用电量的增加,家庭火灾发生的频率越来越高.家里一旦发生火灾,如果出现扑救不及时.灭火器材缺乏.以及在场人惊慌失措.逃生迟缓等不利情况下,最终就会导致产生重大的生命财产的损失. 消防部 ...
- 使用.net core构建分布式SAAS系统(目录)
一 前言 二 项目背景 三 项目架构-从单体应用到微服务 四 大数据量下的分库分表 五 缓存处理--进程内缓存与Redis的使用 六 使用MNS队列来流量削峰 七 百万Job的任务调度系统 八 每天1 ...
- Riccati方程(微分方程)
形如:$$\frac{dy}{dx}=P(x)y^{2}+Q(x)y+R(x)$$ 其中P(x).Q(x).R(x)是连续可微函数 或形如 $$\frac{dy}{dx}=ay^{2}+\frac{k ...
- 一入OI深似海 2 —— 初中三年,颓废PJ
初中,OI似乎没有真正进入我的生活. 三年PJ在我的生活中占比很少. 每天都是平淡无奇的文化课,晚上在写完作业之后还能休息一会儿. 每周六下午的OI课很短暂, 大部分时间我还是把我的重心放在学习上. ...
- Django在根据models生成数据库表时报 __init__() missing 1 required positional argument: 'on_delete'
from django.db import models # Create your models here. class Category(models.Model): caption = mode ...
- jstl的foreach标签
jsp支持丰富的jstl标签语言(需要jar包支持),其中list循环(迭代)用的是<c:forEach></c:forEach>标签. 这个标签的作用就是迭代输出标签内部的内 ...
- this.$router.push、replace、go的区别
1.this.$router.push() 描述:跳转到不同的url,但这个方法会向history栈添加一个记录,点击后退会返回到上一个页面. 用法: 2.this.$router.replace() ...
- 《转载》最新鲜最详细的Android SDK下载安装及配置教程
Android开发环境搭建可以分: 第一步.安装JDK: 第二步.安装Eclipse: 第三步.下载并安装AndroidSDK: 下面详细介绍. 第一步.安装JDK Android开发工具要求必须 ...
- 读取导入csv csv报错iterable expected, not float
示例代码import pandas as pdimport reimport csv data = pd.read_csv('nuojia.csv', encoding='utf-8')# print ...