In SQL Server, all rows of data are duplicated and cannot be updated or deleted. The problem is usually the table without a primary key. Error: Check whether the table has a primary key. If not, you have
In SQL server, all rows of data are duplicated and cannot be updated or deleted. The problem is usually the table without a primary key. Error: Check whether the table has a primary key. If not, you have
The SQL Server Data row cannot delete or copy the table structure.
[Date:] Source: Linux community Author: cjr15233851143 [Font:]
The following are the two problems I encountered when working on the system:
<1>. SQL server has duplicate rows of data and cannot be updated or deleted.
It is usually a table without a primary key.
Error:
Check whether the table has a primary key. If not, use a temporary table to delete duplicate rows.
Example:
Method 1:
Delete from tab_test2 where id = (select max (id) from tab_test2 group by id, uid having count (1)> 1)
Method 2: Note: # t is a temporary table, which can be found under the temporary table node in the tempdb database and will disappear after the SQL Server service is restarted.
Select id, uid into # t from tab_Test2 group by id, uid
Truncate table tab_Test2
Insert into tab_Test2 select * from # t
<2>.Copy the structure of other tables to a specified table.
For example:
There are three tables as follows::
Consider the following question: is the specified table empty?