0

I read the similar issue shared on stack overflow regarding DELETE command is not execute a query.

I am a beginner level on SQL and was trying to understand identity column action so I created a super basic studentinfo table and put firstname, lastname, and id columns.

ID selected as identity column and incremental is setup 5. That is the summary of the table. And created couple rows for the table.

Now when I execute DELETE FROM StudentInfo WHERE StudentId like '0213422' returns 0 rows affected and of course not deleting that row.

Anyone tell why is that happening?

Thanks in advance

5
  • It ID is incremental:5, how come you expect to have such an id: 0213422?? BTW, there is no row with the ID: 0213422 in the table. Also, please try DELETE FROM StudentInfo WHERE StudentId like '0213422%' Commented Nov 20, 2018 at 15:17
  • @ErayBalkanli This not real application for any client. Just playing around so any reason to change studentid and incremental setup. By the way I added couple rows to table. I will update the above statement. Tesekkurler :) Commented Nov 20, 2018 at 15:20
  • Dont use Like, use ` = ` instead Commented Nov 20, 2018 at 15:22
  • @JoakimDanielson. Thanks that worked. Sorry for very simple question Commented Nov 20, 2018 at 15:25
  • Are you SURE you have ID set up as an IDENTITY column? If so, values would never start with a text "0". Commented Nov 20, 2018 at 15:59

2 Answers 2

2

You can either use:

where StudentId like '%0213422%'

or

where StudentId = '0213422'

Like can be used with placeholders like '%' or '_'

'%' - indicates that there could be multiple characters in the placeholder.

'_' - indicates that there is exactly one character as a placeholder

ID | Stuff

1 | Foobar

2 | Fobar

where Stuff like 'F%bar' --would return both row

where Stuff like 'F_bar' --would retun only the second row
Sign up to request clarification or add additional context in comments.

3 Comments

Actually, like '0213422' works the same as = '0213422'. It will find just the one with the exact value '0213422'
Yes but i dont think that like '0213422' is the prefered way to use a "like" clause. I asume he didn't know how Like works, so i explained it
On that I also agree
0

Normally an identity column is type bigint or int and contains simply spoken just numbers. So I wonder that a value can have a leading 0.
I suggest to use a select statement first to see, what is in the result set like

Select * FROM Studentinfo WHERE StudentId like '%213422' 

or

Select * FROM Studentinfo WHERE StudentId >=213422

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.