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 删除所有表和递归查询、数字类型转为字符串的更多相关文章

  1. Sql Server删除数据表中重复记录 三种方法

    本文介绍了Sql Server数据库中删除数据表中重复记录的方法. [项目]数据库中users表,包含u_name,u_pwd两个字段,其中u_name存在重复项,现在要实现把重复的项删除![分析]1 ...

  2. Sql Server 删除所有表

    如果由于外键约束删除table失败,则先删除所有约束: --/第1步**********删除所有表的外键约束*************************/ DECLARE c1 cursor f ...

  3. sql server 删除所有表、视图、存储过程

    如果由于外键约束删除table失败,则先删除所有约束:   --/第1步**********删除所有表的外键约束*************************/   DECLARE c1 curs ...

  4. Sql Server 删除所有表 脚本

    如果由于外键约束删除table失败,则先删除所有约束: --/第1步**********删除所有表的外键约束*************************/ DECLARE c1 cursor f ...

  5. sql server 删除所有表和存储过程

    1.删除外键约束 DECLARE c1 cursor for select 'alter table ['+ object_name(parent_obj) + '] drop constraint ...

  6. Sql Server 删除所有表(转)

    http://www.cnblogs.com/jys509/p/3589468.html  首先必须要清空所有表的外键 DECLARE c1 cursor for select 'alter tabl ...

  7. SQL Server删除表信息的三种方法

    1.使用DELETE实现SQL Server删除表信息 (1)删除表中的全部信息 USE student GO DELETE student      --不加where条件,删除表中的所有记录 go ...

  8. SQL server 数据库用户表名称

    转自(http://blog.163.com/jlj_sk/blog/static/22579293200861422833924/) 取得SQL server 数据库中 所有用户表名称 select ...

  9. SQL Server数据库、表、数据类型基本概念

    一.SQL Server的数据存储结构 SQL Server是一个数据库管理系统,需要以有效方式存储高容量数据.要更好地理解SQL Server处理数据的方式,就需要了解数据的存储结构. 1.文件类型 ...

随机推荐

  1. Java基础系列--02_运算符和程序的语句

    运算符: (1)算术运算符: +,-,*,/,%,++,--(加.减.乘.除.取余.自增,自减) ++和--的注意事项: a:他们的作用是自增或者自减 b:使用 1.单独使用 放在操作数据的前面和后面 ...

  2. ASP.NET MVC2未能加载类型“System.Web.Mvc.ViewPage的解決方法

    问题描述: “/”应用程序中的服务器错误. 分析器错误 说明: 在分析向此请求提供服务所需资源时出错.请检查下列特定分析错误详细信息并适当地修改源文件. 分析器错误消息: 未能加载类型“System. ...

  3. Kafka Frequently Asked Questions

    This is intended to be an easy to understand FAQ on the topic of Kafka. One part is for beginners, o ...

  4. Luogu1574 超级数

    Luogu1574 超级数 \(n\) 次询问不超过 \(a_i\) 的最大反素数 \(n\leq10^5,\ a_i\leq10^{17}\) 数论 似乎重题 bzoj1053 [HAOI2007] ...

  5. redis 初步认识二(c#调用redis)

    前置:服务器安装redis 1.引用redis 2.使用redis(c#) 一 引用redis  (nuget   搜索:CSRedisCore) 二 使用redis(c#) using System ...

  6. ABP之模块系统

    简介 ASP.NET Boilerplate提供了构建模块的基础结构,并将它们组合在一起以创建应用程序. 模块可以依赖于另一个模块. 通常,一个程序集被视为一个模块. 如果创建具有多个程序集的应用程序 ...

  7. redis 的过期策略都有哪些?内存淘汰机制都有哪些?

    面试题 redis 的过期策略都有哪些?内存淘汰机制都有哪些?手写一下 LRU 代码实现? 面试官心理分析 如果你连这个问题都不知道,上来就懵了,回答不出来,那线上你写代码的时候,想当然的认为写进 r ...

  8. Graphic

    画圆操作 package demo1; import java.awt.Graphics; import javax.swing.*; import javax.swing.JPanel; publi ...

  9. springboot mybatis 整合

    新建项目在上一篇. 第二步:创建表和相应的实体类 实体类:user.java package com.qtt.im.entity; import java.io.Serializable; publi ...

  10. 最大k乘积问题

    68.最大k乘积问题 (15分)C时间限制:3000 毫秒 | C内存限制:3000 Kb题目内容:设I是一个n位十进制整数.如果将I划分为k段,则可得到k个整数.这k个整数的乘积称为I的一个k乘积. ...