I have a SQL 2005 database with approx 250 tables. I want to temporarily enable ON DELETE CASCADE to all of the Foreign Keys so that I can do a bulk delete easily. I then want to turn off ON DELETE CASCADE on all Foreign Keys. The only way I know of doing this, is to use Management Studio to
Tag: sql-server
conditional unique constraint
I have a situation where i need to enforce a unique constraint on a set of columns, but only for one value of a column. So for example I have a table like Table(ID, Name, RecordStatus). RecordStatus can only have a value 1 or 2 (active or deleted), and I want to create a unique constraint on (ID, RecordStatus) only
Will a SQL Server Job skip a scheduled run if it is already running?
If you schedule a SQL Server job to run every X number of minutes, and it does not finish the previous call before the # of minutes is up, will it skip the run since it is already running, or will it …
How to avoid Sql Query Timeout
I have RO access on a SQL View. This query below times out. How to avoid this? The error message I get is: Msg 121, Level 20, State 0, Line 0 A transport-level error has occurred when receiving results from the server (provider: TCP Provider, error: 0 – The semaphore timeout period has expired.) Answer Although there is clearly some
Foreign key constraint may cause cycles or multiple cascade paths?
I have a problem when I try to add constraints to my tables. I get the error: Introducing FOREIGN KEY constraint ‘FK74988DB24B3C886’ on table ‘Employee’ may cause cycles or multiple cascade paths. …
Select n random rows from SQL Server table
I’ve got a SQL Server table with about 50,000 rows in it. I want to select about 5,000 of those rows at random. I’ve thought of a complicated way, creating a temp table with a “random number” column, …
Getting new IDs after insert
I’m inserting a bunch of new rows into a table which is defined as follows: using the following insert: when I’ve finished, I’d like to know the IDs of all the newly inserted rows. SCOPE_IDENTITY() only returns the ID last row inserted. How can I get all the new IDs? One method that springs to mind would be to grab
WHERE IS NULL, IS NOT NULL or NO WHERE clause depending on SQL Server parameter value
I have a stored procedure in SQL Server 2000 that performs a search based on parameter values. For one of the parameters passed in, I need a different WHERE clause depending on its value – the problem …
How can I compare time in SQL Server?
I’m trying to compare time in a datetime field in a SQL query, but I don’t know if it’s right. I don’t want to compare the date part, just the time part. I’m doing this: Is it correct? I’m asking this because I need to know if 08:00:00 is less or greater than 07:30:00 and I don’t want to compare
How to update rows with a random date
I have a simple SQL table which has a DateTime column. I would like to update all the rows (>100000 rows) with a random date. Is there a simple way to do this a SQL Query?