Thursday, October 30, 2014

Eclipse - Configuration - how to change project type

Background:
I have imported a java project (not sure the project was created as Java Project) in Eclipse but it wasn't giving any IntelliSense (code suggestion), errors were not marked, build automatically etc. "(Project) - Properties" (alt + enter) was not providing all the option usually seen in regular java project. That led me to think that eclipse is not able to recognize this project as valid java project.

Solution:
Change the project type solved the issue. Actually I had to deselect 'Java' - Save and than open again and select 'Java' to make it work.

How to change project type in eclipse
1. "(Project) - Properties" (alt + enter)
2. From left navigation panel, select 'Project Facets'
3. From right side, select 'Java' and appropriate version from drop down. 
4. Apply and Save

When selecting 'Java' in project facet first time:
When 'Java' is selected as first time facet for a project, a new link 'Further configuration available...' will appear at the bottom. That will allow to specify source and build path. Always good idea to check that link

Few shortcuts:
1. "Alt + Enter" - will open the Project Properties 



Tuesday, October 14, 2014

SQL Server - Coding - Update data in tables related by foreign constraint

Environment: SQL Server 2008

Background: I need to update id column value of a table which has corresponding data in a child table and integrity enforced by foreign key constraint. Relationship between tables and data excerpt present below. Need to change 'ROLE_EXEMPTION' with value 'ROLE_AMLM_QA1_EXEMPTION'.

Table relationship:
















Data in tables:















Script to fulfill the need:

DECLARE @changedValue VARCHAR(100) = 'ROLE_AMLM_QA1_EXCEMPTION',
@originalValue VARCHAR(100) = 'ROLE_EXEMPTION'
;

-- Disable all table constraints
ALTER TABLE wk_sec_role_resource_mapping NOCHECK CONSTRAINT ALL;

-- Update parent table record
UPDATE wk_sec_roles SET role_id=@changedValue WHERE role_id=@originalValue;
-- Update child table record
UPDATE wk_sec_role_resource_mapping SET role_FK=@changedValue WHERE role_FK=@originalValue;

-- Enable all table constraints

ALTER TABLE wk_sec_role_resource_mapping CHECK CONSTRAINT ALL;


Necessary info:

-- Disable all table constraints
ALTER TABLE MyTable NOCHECK CONSTRAINT ALL

-- Enable all table constraints
ALTER TABLE MyTable CHECK CONSTRAINT ALL

-- Disable single constraint
ALTER TABLE MyTable NOCHECK CONSTRAINT MyConstraint

-- Enable single constraint
ALTER TABLE MyTable CHECK CONSTRAINT MyConstraint
-- disable all constraints

EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"