Hello Experts,
I have one query in sql server 2008.
I have create one table in this table there are not any Primary Key.
my table structure like this.
ID Name
-----------
1 Test1
2 Test2
3 Test3
4 Test4
1 Test1
2 Test2
3 Test3
4 Test4
first time I have add id no 1,2,3,4 this record and second time I have add another 1,2,3,4 Records.
I have delete last 4 records but id is same.
it is possible in single Query?
Loading
Jiteendra SampathiraoPosted May 7, 2011, 3:06 AM
As vijay said that is not a good practice. And you want to delete the last 4 records you have to write the where clause nothing but Condition.So there is only two columns. so when u check the condition like "Where Id=1" like that those two columns which are having id value 1 will be deleted.
Finally you have only one choice. Open Sql Sever Manager-->Return all rows--> right click on the records-->delete one by one.
Vijay YadavPosted May 7, 2011, 2:20 AM
As you want to delete last four records but it will delete all the records as the id is same.
And it is bad practice, you should be able to identify the row uniquely.
So, I would suggest make the ID unique or take another column named SrNo keep that column auto-increment and primary key as well.
And you can delete by the same.