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

SQL 中将一个表转化成建表语句的存储过程

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc pGetInsertSQL (@TableName varchar(256))
as
begin
    set nocount on
    declare @sqlstr varchar(4000)
    declare @sqlstr1 varchar(4000)
    declare @sqlstr2 varchar(4000)
    select @sqlstr='select ''insert '+@tablename
    select @sqlstr1=''
    select @sqlstr2=' ('
    select @sqlstr1= ' values ( ''+'
    select @sqlstr1=@sqlstr1+col+'+'',''+' ,@sqlstr2=@sqlstr2+name +',' from (select case
--    when a.xtype =173 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name +')'+' end'
    when a.xtype =104 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(1),'+a.name +')'+' end'
    when a.xtype =175 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
    when a.xtype =61  then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(23),'+a.name +',121)'+ '+'''''''''+' end'
    when a.xtype =106 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name +')'+' end'
    when a.xtype =62  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(23),'+a.name +',2)'+' end'
    when a.xtype =56  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(11),'+a.name +')'+' end'
    when a.xtype =60  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(22),'+a.name +')'+' end'
    when a.xtype =239 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''


相关文档:

SQL Server 2008 案例之微软IT部门

“经过测试我们发现SQL Server 2008当中的备份压缩功能可以1-3倍的压缩比,从而极大的减少备份所需的磁盘空间。”Alexey Yeltsov, 微软系统管理员主管。
微软在全世界共有6万多名员工,在2006年的财政收入超过了500亿美金,与此同时也产生了大量内部数据,公司希望对这些数据进行集中以便提供客户的集成化视图。 ......

SQL中没用集合的minus,用union实现

列出TableA中有的而TableB中没有, 以及B中有而A中没有的记录:
其中两个表的结构相同,选择的Key可以多个
Select Key from
( select * from TableA
Union select * from TableB
)
group by Key
having count(Key)=1

列出TableA中有的而TableB中没有的记录:
Select Key from
( (select * from TableA
Un ......

50条常用sql语句

Student(S#,Sname,Sage,Ssex) 学生表
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表
问题:
1、查询“”课程比“”课程成绩高的所有学生的学号;
  SELECT a.S# from (SELECT s#,score from SC WHERE C#='001') a,
  (SELECT s#,score  fr ......

sql数据库:如何在一个表中填加或者删除一个字段!


如要在一个hwsp表中填加字段:ylxs
alter table hwsp add column ylxs
ALTER TABLE 表 {ADD ADD{COLUMN 字段类型 [ (字长)] [NOT NULL]     [CONSTRAINT 索引 ] |
     ALTER COLUMN 字段类型 [(字长)] |
     CONSTRAINT 多重字段索引 } |
 &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号