Home > Database > Mysql Tutorial > body text

SQL Server 数据行无法删除 和 复制表结构

WBOY
Release: 2016-06-07 17:20:50
Original
1246 people have browsed it

sql server中多行所有数据重复,无法更新或删除问题通常是在没有主键的情况下的表.错误:先确认一下表中有没有主键,要是没有就得

SQL Server 数据行无法删除 和 复制表结构

[日期:2012-09-25] 来源:Linux社区  作者:cjr15233661143 [字体:]

下面是我在做系统时遇到的两个问题

.sql server中多行所有数据重复,无法更新或删除问题

通常是在没有主键的情况下的表.

错误:

先确认一下表中有没有主键,,要是没有就得使用临时表来实现删除重复的行。

示例:

方法一:

delete from tab_test2 where id=(select max(id) from tab_test2 group by id,uid having count(1)>1) 

方法二:注意:#t是临时表,在tempdb数据库中的临时表节点下可以找到,sqlserver服务重启就会消失的表.

select id,uid into #t from tab_Test2 group by id,uid

truncate table tab_Test2

insert into tab_Test2 select * from #t 

.复制其它表的结构到一指定的表中去 

比如以下的例子:

  有如下三个表:

考虑一个问题,所到的指定表是不是空表?

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!