I have to add a unique constraint to an existing table. This is fine except that the table has millions of rows already, and many of the rows violate the unique constraint I need to add. What is the …
SQL constraint minvalue / maxvalue?
Is there a way to set a SQL constraint for a numeric field that min value should be 1234 and max value should be 4523?
Combining data from different tables to form a news feed
Let’s say I have 2 tables, Message and Product. Whenever a user post a new products or messages, users who subscribe to that particular user will have their feed updated.It is similar to Facebook feed….
sql while loop with date counter
I need to do something like this in sql: How can I do the above correctly in SQL? Basically, my startdate and enddate are strings and not datetimes because my business logic is referencing string column in another table with a date as the name of the column-But I need to loop through a bunch of columns, each column having
Reset or Update Row Position Integer in Database Table
I am working on a stored procedure in SQL Server 2008 for resetting an integer column in a database table. This integer column stores or persists the display order of the item rows. Users are able to drag and drop items in a particular sort order and we persist that order in the database table using this “Order Rank Integer”.
SELECT (* – some_columns) FROM TABLE in SQL
I have a table with many columns among which I’d like to omit a few alone in my ‘select’ query. Something like select (* – columns_to_be_omitted) from myTable. Is there a way to do this, other than listing all the other columns in the query? This is a one-time manual query, so I’m not that concerned about performance. Ease of
Trunc(sysdate) in SQL Server
What is the equivalent of: …in SQL Server 2005? Answer Recommended: This is another alternative, but it’s risky because of casting to a FLOAT. It’s also been demonstrated to not scale performance as well as the DATEADD/DATEDIFF approach.
Efficient way to check if a SQL query will return results
I would like to write a query that simply returns 1 or 0 depending if there will be results. I am thinking to use this That’s the general premise. The final results will actually be a far more complex query, taking one to many parameters and the string built up and executed using sp_executesql My question is lets say the
Insert if not exists Oracle
I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: Is this at all possible with Oracle? Bonus points if you can tell me how to do this in PostgreSQL
How can I print the SQL query executed after Perl’s DBI fills in the placeholders?
I’m using Perl’s DBI module. I prepare a statement using placeholders, then execute the query. Is it possible to print out the final query that was executed without manually escaping the parameters and dropping them into the placeholders? Thanks Answer See Tracing in DBI. The following works using DBD::SQLite but produces a lot of output: Output: <- prepare(‘SELECT … FROM