The safest way to do this is to enforce your business rules using the built-in referential integrity constraints, as Alexander Kuznetsov describes in his article, "Storing intervals of time with no overlaps".

Applying the techniques listed there to your sample table results in the following script:

CREATE TABLE [Z_STORE_TEAM](
    [STORENUM] [int] NOT NULL,
    [TEAM] [varchar](10) NULL,
    [EFFECTIVE] [date] NOT NULL,
    [FINISHED] [date] NULL,
    PRIMARY KEY CLUSTERED 
    (
        [STORENUM] ASC,
        [EFFECTIVE] ASC
    )
) ON [PRIMARY];

INSERT [Z_STORE_TEAM] 
    ([STORENUM], [TEAM], [EFFECTIVE], [FINISHED]) 
VALUES 
    (1, N'1', CAST(0x01380B00 AS Date), CAST(0x81380B00 AS Date)),
    (1, N'2', CAST(0x81380B00 AS Date), NULL),
    (2, N'1', CAST(0x01380B00 AS Date), NULL);


Modifications:

-- New column to hold the previous finish date
ALTER TABLE dbo.Z_STORE_TEAM 
ADD PreviousFinished date NULL;
GO
-- Populate the previous finish date
UPDATE This
SET PreviousFinished = Previous.FINISHED
FROM dbo.Z_STORE_TEAM AS This
CROSS APPLY
(
    SELECT TOP (1) 
        Previous.FINISHED
    FROM dbo.Z_STORE_TEAM AS Previous
    WHERE 
        Previous.STORENUM = This.STORENUM
        AND Previous.FINISHED &lt;= This.EFFECTIVE
    ORDER BY 
        Previous.FINISHED DESC
) AS Previous;
GO
ALTER TABLE dbo.Z_STORE_TEAM 
ADD CONSTRAINT UQ_STORENUM_PreviousFinished
UNIQUE (STORENUM, PreviousFinished);
GO
ALTER TABLE dbo.Z_STORE_TEAM
ADD CONSTRAINT CK_PreviousFinished_NotAfter_Effective
CHECK (PreviousFinished = EFFECTIVE);
GO
ALTER TABLE dbo.Z_STORE_TEAM
ADD CONSTRAINT UQ_STORENUM_FINISHED
UNIQUE (STORENUM, FINISHED);
GO
ALTER TABLE dbo.Z_STORE_TEAM
ADD CONSTRAINT FK_STORENUM_PreviousFinished
FOREIGN KEY (STORENUM, PreviousFinished)
REFERENCES dbo.Z_STORE_TEAM (STORENUM, FINISHED);
GO
ALTER TABLE dbo.Z_STORE_TEAM
ADD CONSTRAINT CK_EFFECTIVE_Before_FINISHED
CHECK (EFFECTIVE &lt; FINISHED);


An attempt to insert the fourth row of sample data now fails with an error message:

INSERT [Z_STORE_TEAM] 
    ([STORENUM], [TEAM], [EFFECTIVE], [FINISHED]) 
VALUES 
    (2, N'2', '20140201', NULL);




Please read Alex's article to understand how these constraints ensure your table data will always be valid. Having a set of constraints enforce your data integrity means no trigger code is required.

What is the correct way to ensure unique entries in a temporal database design?
I have looked many forums for this issue, there are quite a few answers on this topic but none of these have worked for me/match my criteria.

I recently took up Mobile Automation task and hence am completely new  to Appium. I am working with Appium 1.2.0.1 on Windows 7 and trying to automate the native Android Browser(not Chrome or an App) on an Android v4.3 real device. 
I have installed everything according to the instructions. I am using Selenium in Maven Build in JUnit Framework to execute the scripts through Appium. I use Appuim.exe in Admin mode and use the GUI to start the node. Then I run my scripts. 

My issue is that when I try "adb devices" in cmd, I am able to see the device. Whereas, during execution, Appium is throwing an Error "Failed to start an Appium session, err was: Error: Could not find a connected Android device." I tried many troubleshooting options and verified if everything is in place. No luck. Please help.

Below is the trace of Error:

&gt; Checking if an update is available
&gt; Update not available
&gt; Starting Node Server
&gt; info: Welcome to Appium v1.2.0 (REV e53f49c706a25242e66d36685c268b599cc18da5)
&gt; debug: Non-default server args: {"address":"127.0.0.1","fullReset":true,"logNoColors":true,"platformName":"Android","platformVersion":"18","automationName":"Appium","browserName":"Browser"}
&gt; info: Appium REST http interface listener started on 127.0.0.1:4723
&gt; info: LogLevel: debug
&gt; info: --&gt; POST /wd/hub/session {"desiredCapabilities":{"platformVersion":"4.3","browserName":"Browser","platformName":"Android","device":"Android","deviceName":"Android"}}
&gt; debug: Appium request initiated at /wd/hub/session
&gt; info: Retrieving device
&gt; warn:  code=ENOENT, errno=ENOENT, syscall=spawn
&gt; debug: Request received with params: {"desiredCapabilities":{"platformVersion":"4.3","browserName":"Browser","platformName":"Android","device":"Android","deviceName":"Android"}}
&gt; debug: The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : device
&gt; debug: Looks like we want chrome on android
&gt; debug: Creating new appium session fa19e382-c178-4e6b-8150-a386a51bee39
&gt; debug: Preparing device for session
&gt; debug: Not checking whether app is present since we are assuming it's already on the device
&gt; debug: Checking whether adb is present
&gt; debug: Using adb from C:\Android\android-sdk\platform-tools\adb.exe
&gt; debug: Trying to find a connected android device
&gt; debug: Getting connected devices...
&gt; debug: executing: "C:\Android\android-sdk\platform-tools\adb.exe" devices
&gt; debug: Could not find devices, restarting adb server...
&gt; debug: executing: "C:\Android\android-sdk\platform-tools\adb.exe" kill-server
&gt; warn:  code=ENOENT, errno=ENOENT, syscall=spawn
&gt; warn:  code=ENOENT, errno=ENOENT, syscall=spawn
&gt; debug: Getting connected devices...
&gt; debug: executing: "C:\Android\android-sdk\platform-tools\adb.exe" devices
&gt; debug: Could not find devices, restarting adb server...
&gt; debug: executing: "C:\Android\android-sdk\platform-tools\adb.exe" kill-server
&gt; error: Error killing ADB server, going to see if it's online anyway
&gt; debug: Getting connected devices...
&gt; debug: executing: "C:\Android\android-sdk\platform-tools\adb.exe" devices
&gt; debug: Could not find devices, restarting adb server...
&gt; warn:  code=ENOENT, errno=ENOENT, syscall=spawn
&gt; warn:  code=ENOENT, errno=ENOENT, syscall=spawn
&gt; debug: executing: "C:\Android\android-sdk\platform-tools\adb.exe" kill-server
&gt; warn:  code=ENOENT, errno=ENOENT, syscall=spawn
&gt; error: Error killing ADB server, going to see if it's online anyway
&gt; warn:  code=ENOENT, errno=ENOENT, syscall=spawn
&gt; info: &lt;-- POST /wd/hub/session 500 20314.056 ms - 206 
&gt; debug: Getting connected devices...
&gt; debug: executing: "C:\Android\android-sdk\platform-tools\adb.exe" devices
&gt; debug: Cleaning up appium session
&gt; error: Failed to start an Appium session, err was: Error: Could not find a connected Android device.
&gt; debug: Error: Could not find a connected Android device.
&gt;     at ADB.getDevicesWithRetry (C:\Selenium\AppiumForWindows-1.2.0.1\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:600:15)
&gt;     at androidCommon.prepareActiveDevice (C:\Selenium\AppiumForWindows-1.2.0.1\Appium\node_modules\appium\lib\devices\android\android-common.js:349:12)
&gt;     at null.&lt;anonymous&gt; (C:\Selenium\AppiumForWindows-1.2.0.1\Appium\node_modules\appium\lib\devices\android\android-common.js:289:26)
&gt;     at C:\Selenium\AppiumForWindows-1.2.0.1\Appium\node_modules\appium\node_modules\async\lib\async.js:610:21
&gt;     at C:\Selenium\AppiumForWindows-1.2.0.1\Appium\node_modules\appium\node_modules\async\lib\async.js:249:17
&gt;     at iterate (C:\Selenium\AppiumForWindows-1.2.0.1\Appium\node_modules\appium\node_modules\async\lib\async.js:149:13)
&gt;     at C:\Selenium\AppiumForWindows-1.2.0.1\Appium\node_modules\appium\node_modules\async\lib\async.js:160:25
&gt;     at C:\Selenium\AppiumForWindows-1.2.0.1\Appium\node_modules\appium\node_modules\async\lib\async.js:251:21
&gt;     at C:\Selenium\AppiumForWindows-1.2.0.1\Appium\node_modules\appium\node_modules\async\lib\async.js:615:34
&gt;     at androidCommon.prepareEmulator (C:\Selenium\AppiumForWindows-1.2.0.1\Appium\node_modules\appium\lib\devices\android\android-common.js:339:5)
&gt; debug: Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Could not find a connected Android device.)","origValue":"Could not find a connected Android device."},"sessionId":null}


And here is my code:

if (runEnv.equals("Android")) 
        {
            DesiredCapabilities capabilities = new DesiredCapabilities();
              capabilities.setCapability("device","Android");
              capabilities.setCapability("deviceName","Android");
              capabilities.setCapability("platformName","Android");
              capabilities.setCapability("browserName", "Browser");
              capabilities.setCapability("platformVersion", "4.3");

              try {
                driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }

            driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
        }


Please help!

Thanks,
Arpitha
