SELECT d.ID, d.LogDate, d.Name, d.Department
FROM DeviceLogs d, (SELECT MIN(LogDate) FROM DeviceLogs GROUPBY Name) s
WHERE s.MIN(LogDate) = d.LogDate
SELECT ID, MIN(LogDate) AS LogDate, Name, Department
GROUPBY ID, Name, Department;
I have written a small sql script to drop a table and recreate it but it is failing, I tried to drop all existing indexes on the table and column then trying to drop the column, but still fails by saying there is one constraint that's missing, and I don't know why but that constraint doesn't exist in database.
Here is the script that I am writing
DECLARE @ConstraintName nvarchar(200);
DECLARE @TableName nvarchar(500)='ApplicationData';
DECLARE @ColumnName nvarchar(500)='ReportingFpl';
SET NOCOUNT ONSET xact_abort ONWHILE 0=0 BEGINSET @constraintName = (
WHERE table_name = @tableName and column_name = @columnName );
IF @constraintName isnull BREAK;
EXEC ('alter table "'+@tableName+'" drop constraint "'+@constraintName+'"');
ENDALTERTABLE dbo.ApplicationData DROPCOLUMN ReportingFpl;
Msg 5074, Level 16, State 1, Line 16
The index 'IX_ApplicationData_ApplicationId-ReportingFpl_PriorityPoints-ContractorPriorityPoints' is dependent on column 'ReportingFpl'.
Msg 4922, Level 16, State 9, Line 16
ALTER TABLE DROP COLUMN ReportingFpl failed because one or more objects access this column.
But the constraint 'IX_ApplicationData_ApplicationId-ReportingFpl_PriorityPoints-ContractorPriorityPoints' doesn't exist in the constraint table at all.
Can anybody please help me in resolving this issue, any link, any suggestion or code snippet helps greatly.
I have dedicated server with 8 Gb RAM.I have developed the CRM when multiple user working at a time Sql server working very slow task is going on suspended.
Sql server 2008 R2 Express Edition
Maximum Memory=2147483647 Mb
Minimum Memory Per query=1024 kb