3

我正在构建 JSP 应用程序,我想在其中对特定表执行以下操作

  • 显示数据
  • 删除数据

我已经完成了数据的显示,但是:

如果表没有任何主键,如何删除数据库中的一行?(删除操作不依赖于该行的任何值)

假设这里是 may 表 -->> mytemp 这里是数据

Name | RollNo
ABC  |  98
XYZ  |  76
ABC  |  98
XYZ  |  76

此表中没有键,我想删除第 3 条记录。我怎样才能做到这一点 ?

4

3 回答 3

4

You can choose any available column you think most suitable: e.g.

DELETE FROM table_name WHERE column_name  = 'valuse'    

without column_name you can delete all rows only.

column_name does not has to be primary key, but all rows with column_name = 'valuse' will be deleted.


EDIT
To delete:

  DELETE FROM table_name WHERE Name = 'ABC' AND  RollNo  = 98;       

Name and RollNo may not be primary key.

Delete only third row:

DELETE FROM table_name  
WHERE ('ABC',98) IN ( SELECT TOP 1 Name, Rollno 
                      FROM table_name 
                      ORDER BY Name,RollNo DES)   

Second way: if TOP not works

DELETE FROM table_name  
WHERE ('ABC',98) IN ( SELECT  Name, Rollno 
                      FROM table_name 
                      ORDER BY Name,RollNo DES LIMT 1)   

CAUTION: it will delete one, which one I am not sure.

Give it a try!!

于 2012-12-27T10:03:29.610 回答
1

If you want to delete all records you can use

delete from TABLE_NAME

and if you have any difference in the rows in the DB you can add where clause as well like

delete from TABLE_NAME where COL1=XXX AND/OR COL@ =YYY

etc...

delete from TABLE_NAME where RollNo= RollNo_HERE AND Name = 'NAME_HERE'

Hope this will help you

于 2012-12-27T10:03:47.090 回答
1

尝试这个:

DELETE t
FROM YourTable t
WHERE t.Name    = 'Selected Name'
  AND t.RollNo = 'Selected RollNo';
于 2012-12-27T10:12:27.643 回答