易截截图软件、单文件、免安装、纯绿色、仅160KB

将数据库表中的数据转为sql中的insert语句

 set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
--将表数据生成SQL脚本的存储过程
ALTER PROCEDURE [UspOutputData]
@tablename sysname
AS
declare @column varchar(1000)
declare @columndata varchar(1000)
declare @sql varchar(4000)
declare @xtype tinyint
declare @name sysname
declare @objectId int
declare @objectname sysname
declare @ident int
set nocount on
set @objectId=object_id(@tablename)
if @objectId is null -- 判断对象是否存在
begin
print 'The object not exists'
return
end
set @objectname=rtrim(object_name(@objectId))
if @objectname is null or charindex(@objectname,@tablename)=0 --此判断不严密
begin
print 'object not in current database'
return
end
if OBJECTPROPERTY(@objectId,'IsTable') < > 1 -- 判断对象是否是table
begin
print 'The object is not table'
return
end
select @ident=status&0x80 from syscolumns where id=@objectid and status&0x80=0x80
if @ident is not null
print 'SET IDENTITY_INSERT '+@TableName+' ON'
declare syscolumns_cursor cursor
for select c.name,c.xtype from syscolumns c where c.id=@objectid order by c.colid
open syscolumns_cursor
set @column=''
set @columndata=''
fetch next from syscolumns_cursor into @name,@xtype
while @@fetch_status < >-1
begin
if @@fetch_status < >-2
begin
if @xtype not in(189,34,35,99,98) --timestamp不需处理,image,text,ntext,sql_variant 暂时不处理
begin
set @column=@column+case when len(@column)=0 then'' else ','end+@name
set @columndata=@columndata+case when len(@columndata)=0 then '' else ','','','
end
+case when @xtype in(167,175) then '''''''''+'+@name+'+''''''''' --varchar,char
when @xtype in(231,239) then '''N''''''+'+@name+'+''''''''' --nvarchar,nchar
when @xtype=61 then '''''''''+co


相关文档:

Sql 查询当天、本周、本月记录

Sql代码:Powered by chenjiazi
--查询当天:   
select * from info where DateDiff(dd,datetime,getdate())=0   
  
--查询24小时内的:   
select * from info where DateDiff(hh,datetime,getDate())<=24   
  
--info为表名,datetime为数 ......

SQL重复记录查询删除

1
、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select

*

from
people
where
peopleId
in
(
select
   peopleId  
from
   people  
group
  
by
   peopleId  
having
  
cou ......

关于时间段的SQL(Orcale、SQL Server)查询

一、Orcale 时的查询
String hql = "from SmsTemplate t where 1=1 ";
 if (model != null && !"".equals(model.getEndTimes())&& null!=model.getEndTimes() ) {
   SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd"); //格式化当前系统日期
   Date ......

用SQL语句修改SQL表结构

最近修改数据库已经存在的表结构,发现用SQL语句能很好的修改表的结构。SQL数据库记录数非常庞大,如果想修改表的字段类型,使用企业管理器来更改字段类型,很多时候会超时,更改不成功,这个时候,可以用SQL语句来更改,以下为相应的代码实例:
1.更改字段类型长度
alert table 表 alert column 字段名 类型的长度
eg: ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号