使用 text、ntext 和 image 函数
有两个 text、ntext 和 image 函数专门用于对 text、ntext 和 image 数据所进行的操作: TEXTPTR 返回 binary(16) 对象,该对象包含指向 text、ntext 或 image 实例的指针。指针一直有效,直到删除该行。
TEXTVALID 函数用来检查指定的文本指针是否有效。
文本指针被传递到用于操作 text、ntext 和 image 数据的 READTEXT、UPDATETEXT、WRITETEXT、PATINDEX、DATALENGTH 和 SET TEXTSIZE Transact-SQL 语句。在 Transact-SQL 语句中,总是使用数据的指针或地址来引用 text、ntext 和 image 数据。下面的示例使用 TEXTPTR 函数来查找与 pubs 数据库的 pub_info 表中 pub_id 0736 相关联的 text 列 (pr_info)。下例首先声明一个局部变量 @val。然后将文本指针(长二进制字符串)置于 @val 中,并将其作为参数提供给 READTEXT 语句,该语句将返回从第五个字节(偏移量为 4)开始的 10 个字节。USE pubs
DECLARE @val varbinary(16)
SELECT @val = textptr(pr_info) FROM pub_info
WHERE pub_id = '0736'
READTEXT pub_info.pr_info @val 4 4下面是结果集:(1 row(s) affected)pr_info
----------------------------------------
yet支持使用 CAST 函数进行从 text 到 varchar、从 ntext 到 nvarchar 和从 image 到 varbinary 或 binary 的显式转换,但 text 或 image 数据将截断为 8,000 个字节,ntext 数据将截断为 4,000 个字符(8,000 个字节)。从 text、ntext 或 image 到其它数据类型的转换(无论是显式的还是隐性的)都不支持。但是,可以对 text、ntext 或 image 数据进行间接转换,例如: CAST( CAST( text_column_name AS VARCHAR(10) ) AS INT )。
有两个 text、ntext 和 image 函数专门用于对 text、ntext 和 image 数据所进行的操作: TEXTPTR 返回 binary(16) 对象,该对象包含指向 text、ntext 或 image 实例的指针。指针一直有效,直到删除该行。
TEXTVALID 函数用来检查指定的文本指针是否有效。
文本指针被传递到用于操作 text、ntext 和 image 数据的 READTEXT、UPDATETEXT、WRITETEXT、PATINDEX、DATALENGTH 和 SET TEXTSIZE Transact-SQL 语句。在 Transact-SQL 语句中,总是使用数据的指针或地址来引用 text、ntext 和 image 数据。下面的示例使用 TEXTPTR 函数来查找与 pubs 数据库的 pub_info 表中 pub_id 0736 相关联的 text 列 (pr_info)。下例首先声明一个局部变量 @val。然后将文本指针(长二进制字符串)置于 @val 中,并将其作为参数提供给 READTEXT 语句,该语句将返回从第五个字节(偏移量为 4)开始的 10 个字节。USE pubs
DECLARE @val varbinary(16)
SELECT @val = textptr(pr_info) FROM pub_info
WHERE pub_id = '0736'
READTEXT pub_info.pr_info @val 4 4下面是结果集:(1 row(s) affected)pr_info
----------------------------------------
yet支持使用 CAST 函数进行从 text 到 varchar、从 ntext 到 nvarchar 和从 image 到 varbinary 或 binary 的显式转换,但 text 或 image 数据将截断为 8,000 个字节,ntext 数据将截断为 4,000 个字符(8,000 个字节)。从 text、ntext 或 image 到其它数据类型的转换(无论是显式的还是隐性的)都不支持。但是,可以对 text、ntext 或 image 数据进行间接转换,例如: CAST( CAST( text_column_name AS VARCHAR(10) ) AS INT )。
where newfield not in(
select min(newfield) from 表 group by 除newfield外的所有字段
)alter table 表 drop column newfield
where newfield not in(
select min(newfield) from 表 group by 除newfield外的所有字段和image列
)alter table 表 drop column newfield
如果有ID字段,就是具有唯一性的字段delect table where id not in ( select max(id) from table group by col1,col2,col3...
)
group by 子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同。
2,如果是判断所有字段也可以这样
select * into #aa from table group by id1,id2,....
delete table
insert into table
select * from #aa
3,没有ID的情况select identity(int,1,1) as id,* into #temp from tabel
delect # where id not in (
select max(id) from # group by col1,col2,col3...)
delect table
inset into table(...)
select ..... from #temp
col1+','+col2+','...col5 联合主键
select * from table where col1+','+col2+','...col5 in ( select max(col1+','+col2+','...col5) from table
where having count(*)>1
group by col1,col2,col3,col4
)
group by 子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同。2,
select identity(int,1,1) as id,* into #temp from tabel
select * from #temp where id in (
select max(id) from #emp where having count(*)>1 group by col1,col2,col3...)