How to avoid duplicate entries without primary key and unique key?

I want to know whether it is possible to avoid duplicate entries or data without any keys or group by statement


If you want to suppress duplicates when querying, use SELECT DISTINCT.

If you want to avoid putting duplicates into a table, just don't insert records that are already there. It doesn't matter whether you have a primary/unique key: those will make the database not allow duplicate records, but it's still up to you to avoid trying to insert duplicates (assuming you want your queries to succeed).

You can use SELECT to find whether a record already exists before trying to insert it. Or, if you want to be fancy, you can insert the new records into a temporary table, use DELETE to remove any that are already present in the real table, then use INSERT ... SELECT to copy the remaining records from the temporary table into the real one.

Create Unique key constrait.

ALTER TABLE Comment ADD CONSTRAINT uc_Comment UNIQUE (CommentId, Comment)

In above case Comment duplication will not be done as we are creating the unique combination of COmmentId and Comment.

Hope this helps.

More info : OR

SQL Server 2005 How Create a Unique Constraint?

Need Your Help

getting the X/Y coordinates of a mouse click on an image with jQuery


I would like to use jQuery to get the X/Y coordinates of a click event on an image. The coordinates should be relative to the image, not relative to the whole page

Assigning multiple css rule's to an element in javascript

javascript html css

Here is few line of java script code to create a div element dynamically. But my doubt is after create that element, is there any short-cut way to assign multiple css rules instead of typing