Tính khoản cách giữa 2 điểm bằng sql server và C#

sql server 

 --[dbo].[sp_DuAnGetKhoangCach] 10.7756587, 106.70042379999995, 0.5

CREATE PROCEDURE [dbo].[sp_DuAnGetKhoangCach]

    @ZipLatitude float, 
    @ZipLongitude float,
    @Radius  float
AS  
SELECT * FROM DuAn

WHERE dbo.TinhKhoanCach2Diem(lat, lng, @ZipLatitude, @ZipLongitude) < @Radius



CREATE FUNCTION TinhKhoanCach2Diem(
    @Latitude1 float,
    @Longitude1 float,
    @Latitude2 float,
    @Longitude2 float
)
RETURNS float 
AS  
    BEGIN 
    -- CONSTANTS
    DECLARE @EarthRadiusInMiles float;
    SET @EarthRadiusInMiles = 6371 -- 3959 for miles, 6371 for KM

    DECLARE @PI  float;
    SET @PI = PI();
    -- RADIANS conversion
    DECLARE @lat1Radians float;
    DECLARE @long1Radians float;
    DECLARE @lat2Radians float;
    DECLARE @long2Radians float;
    SET @lat1Radians = @Latitude1 * @PI / 180;
    SET @long1Radians = @Longitude1 * @PI / 180;
    SET @lat2Radians = @Latitude2 * @PI / 180;
    SET @long2Radians = @Longitude2 * @PI / 180;
    RETURN Acos(
    Cos(@lat1Radians) * Cos(@long1Radians) * Cos(@lat2Radians) * Cos(@long2Radians) + 
    Cos(@lat1Radians) * Sin(@long1Radians) * Cos(@lat2Radians) * Sin(@long2Radians) + 
    Sin(@lat1Radians) * Sin(@lat2Radians)
    ) * @EarthRadiusInMiles;
END

C#

/// <summary>
/// Specifies a Latitude / Longitude point.
/// </summary>
public class LatLng
{
    public double Latitude { get; set; }
    public double Longitude { get; set; }

    public LatLng(){
    }

    public LatLng(double lat, double lng)
    {
        this.Latitude = lat;
        this.Longitude = lng;
    }
}

/// <summary>
/// Returns the distance in miles or kilometers of any two
/// latitude / longitude points.
/// </summary>
/// <param name="pos1">Location 1</param>
/// <param name="pos2">Location 2</param>
/// <param name="unit">Miles or Kilometers</param>
/// <returns>Distance in the requested unit</returns>
public double HaversineDistance(LatLng pos1, LatLng pos2, DistanceUnit unit)
{
    double R = (unit == DistanceUnit.Miles) ? 3960 : 6371;
    var lat = (pos2.Latitude - pos1.Latitude).ToRadians();
    var lng = (pos2.Longitude - pos1.Longitude).ToRadians();
    var h1 = Math.Sin(lat / 2) * Math.Sin(lat / 2) +
                  Math.Cos(pos1.Latitude.ToRadians()) * Math.Cos(pos2.Latitude.ToRadians()) *
                  Math.Sin(lng / 2) * Math.Sin(lng / 2);
    var h2 = 2 * Math.Asin(Math.Min(1, Math.Sqrt(h1)));
    return R * h2;
}

public enum DistanceUnit { Miles, Kilometers };

var Offices = GetMyOfficeList();
for(int i = 0; i< Offices.Count; i++)
{
    Offices[i].Distance = HaversineDistance(
                            coord,
                            new LatLng(Offices[i].Lat, Offices[i].Lng),
                            DistanceUnit.Miles);
}

var closestOffice = Offices.OrderBy(x => x.Distance).Take(1).Single();

 

 

CÁC HÀM XỬ LÝ SỐ TRONG SQL

1/- Hàm ABS :

Với cú pháp hàm ABS  có kết quả trả về là trị tuyệt đối (absolute) của một số bất kỳ. Kết quả trả về luôn luôn là một số dương.

Cú pháp :

SELECT ABS(NUM_EXPR1),ABS(NUMBER_EXPR2),....

[NUMBER_EXRP1,NUMBER_EXPR2 là số muốn trả về giá trị tuyệt đối]

Ví dụ :

Lấy trị tuyệt đối của hai số : 1234.56 và -1234.56

SELECT ABS(1234.56), ABS(-1234.56)

Kết quả:

---------------------------

1234.56    |    1234.56

 

2/- Hàm PI :

Với cú pháp đơn giản của hàm PI  có kết quả trả về là giá trị của hằng số pi trong toán học.

Cú pháp :

SELECT PI()

Kết quả:

---------------------------

3.1415926535897931

 

3/- Hàm POWER :

Với cú pháp hàm POWER  có kết quả trả về là phép tính lũy thừa của một số bất kỳ nào đó theo một số mũ chỉ định.

Cú pháp :

SELECT POWER(NUMBER_EXPR1,Y1),POWER(NUMBER_EXPR2,Y2),...

[NUMBER_EXPR1,NUMBER_EXPR2 là số muốn tính lũy thừa]

[Y1,Y2 là số mũ -- một số dương thực hiện phép lũy thừa.]

Ví dụ:

SELECT POWER(5,2),POWER(2,3)

Kết quả:

------------------

25      |    8

 

4/- Hàm RAND :

Với cú pháp hàm RAND  có kết quả trả về là một số thực ngẫu nhiên( là một số thực dương có miền giá trị từ 0 đến 1) mà hệ thống Microsoft SQL Server tự động tạo ra đảm bảo không trùng lắp.

Cú pháp :

SELECT RAND(NUMBER_EXPR1),RAND(NUMBER_EXPR2),...

[NUMBER_EXPR1,NUMBER_EXPR2 là một giá trị số nguyên có phạm vi không vượt quá phạm vi của kiểu dữ liệu int làm giá trị nguồn cho hệ thống tạo ra số ngẫu nhiên.]

Ví dụ:

SELECT RAND(15),RAND(2)

Kết quả:

-----------------------------------------

0.71385285481053828 | 0.7136106261841817

 

5/- Hàm ROUND :

Với cú pháp hàm ROUND  có kết quả trả về là một số đã được làm tròn.

Cú pháp:

SELECT ROUND(NUMBER_EXPR1,Y1),ROUND(NUMBER_EXPR2,Y2),...

[NUMBER_EXPR1,NUMBER_EXPR2 là số muốn làm tròn có kiểu dữ liệu là số thực.]

[Y1,Y2 là một số nguyên âm hoặc dương dùng để chỉ định vị trí muốn làm tròn, được tính từ vị trí dấu chấm thập phân.]

Ví dụ:

SELECT ROUND(123.4567,2),ROUND(123.4567,0),ROUND(123.4567,-1)

Kết quả:

-----------------------------------------

123.4600 | 123.0000 | 120.0000

 

6/- Hàm SIGN :

Với cú pháp hàm SIGN  có kết quả trả về là một con số quy định dấu của biểu thức số. Kết quả trả về là 1 nếu biểu thức số dương, là -1 nếu biểu thức số âm, là 0 nếu biểu thức số bằng không.

Cú pháp :

SELECT SIGN(NUMBER_EXPR1),SIGN(NUMBER_EXPR2),...

[NUMBER_EXPR1,NUMBER_EXPR2,... là số muốn kiểm tra dấu]

Ví dụ:

SELECT SIGN(-123.45),SIGN(123),SIGN(0)

Kết quả:

---------------------------------------------

-1.00      |      1        |       0

7/- Hàm SQRT :

Với cú pháp hàm SQRT  dùng để thực hiện việc tính căn bậc hai của một số dương bất kỳ. Kết quả trả về là một số dương.

Cú pháp :

SELECT SQRT(NUMBER_EXPR1),SQRT(NUBER_EXPR2),...

[NUMBER_EXPR1,NUMBER_EXPR2,... là số muốn tính căn bậc hai]

Ví dụ:

SELECT SQRT(9),SQRT(5)

Kết quả:

---------------------------------------

3.0            |    2.2360679774997898

 

8/Hàm FLOOR:

Với cú pháp hàm FLOOR dùng để tìm số nguyên lớn nhất nhỏ hơn hoặc bằng giá trị

Cú pháp:

SELECT FLOOR(NUMBER_EXPR1),FLOOR(NUMBER_EXPR2),...

[NUMBER_EXPR1 là số muốn tìm giá trị số nguyên lớn nhất hoặc bằng]

Ví dụ:

SELECT FLOOR(12.3),FLOOR(23.45)

Kết quả:

----------------------------------------

12               |        23

 

9/Hàm CEILING:

Với cú pháp hàm CEILING dùng để tìm số nguyên lớn nhất lớn hơn hoặc bằng giá trị.

Cú pháp:

SELECT CEILING(NUMBER_EXPR1),CEILING(NUMBER_EXPR2)

Ví dụ:

SELECT CEILING(12.3),CEILING(23.45)

Cú pháp:

----------------------------------------

13              |        24

Hiển thị định dạng thời gian thông minh giống Facebook với SQL Server

Nhiều lần, có một yêu cầu để hiển thị ngày cuối cùng hoạt động và thời gian thông minh cho cuối cùng đăng nhập, tin nhắn cuối cùng, trò chuyện cuối cùng, vv.. giống như các mạng xã hội Vì vậy, tôi đã tạo ra một chức năng trong Microsoft SQL, mà sẽ trả về ngày hoạt động cuối cùng hoặc thời gian. Chức năng này sẽ so sánh thời gian ngày cuối cùng với thời gian ngày hiện tại đó là ‘GETDATE ()’ và sẽ trả về kết quả phù hợp.


Đây là các câu lệnh test

SELECT [dbo].[F_GetLastActiveDateTime] (dateadd(day,-1,getdate()))
GO
SELECT [dbo].[F_GetLastActiveDateTime] (dateadd(day,-2,getdate()))
GO
SELECT [dbo].[F_GetLastActiveDateTime] (dateadd(month,-1,getdate()))
GO
SELECT [dbo].[F_GetLastActiveDateTime] (dateadd(month,-2,getdate()))
GO
SELECT [dbo].[F_GetLastActiveDateTime] (dateadd(year,-3,getdate()))
GO
SELECT [dbo].[F_GetLastActiveDateTime] (dateadd(year,-1,getdate()))
GO
SELECT [dbo].[F_GetLastActiveDateTime] (getdate())

 

 

Còn đây là Function dùng để format thời gian:

CREATE FUNCTION [dbo].[F_GetLastActiveDateTime]
(
-- Add the parameters for the function here
@lastActiveDate Datetime
)
RETURNS varchar(30)
AS
BEGIN
DECLARE @LastActivity varchar(100)
SET @LastActivity = '';
-- Add the T-SQL statements to compute the return value here
DECLARE @today datetime, @nowLastActiveDate datetime
DECLARE @years int, @months int, @days int, @hours int, @minutes int, @seconds int, @h int, @m int, @s int
 
SELECT @today = GETDATE()
SELECT @nowLastActiveDate = DATEADD(year,DATEDIFF(year, @lastActiveDate, @today), @lastActiveDate)
 
SELECT @years = DATEDIFF(year, @lastActiveDate, @today) - (CASE WHEN @nowLastActiveDate > @today THEN 1 ELSE 0 END)
SELECT @months = MONTH(@today - @nowLastActiveDate) - 1
SELECT @days = DAY(@today - @nowLastActiveDate) - 1
 
SELECT @h = DATEDIFF(HOUR, @lastActiveDate, @today)
SELECT @m = DATEDIFF(MINUTE, @lastActiveDate, @today)
SELECT @s = DATEDIFF(SECOND, @lastActiveDate, @today)
 
SET @hours = (@h%24)
SET @minutes = (@m%60)
SET @seconds = (@s%60)
 
SET @LastActivity =
(CASE
WHEN @years = 1 THEN '1 year ago'
WHEN @years > 1 THEN convert(varchar(3),@years) + ' years ago'
WHEN @months = 1 THEN '1 month ago'
WHEN @months > 1 THEN convert(varchar(3),@months) + ' months ago'
WHEN @days = 1 THEN '1 day ago'
WHEN @days > 1 THEN convert(varchar(3),@days) + ' days ago'
WHEN @hours = 1 THEN '1 hour ago'
WHEN @hours > 1 THEN convert(varchar(3),@hours) + ' hours ago'
WHEN @minutes = 1 THEN '1 minute ago'
WHEN @minutes > 1 THEN convert(varchar(3),@minutes) + ' minutes ago'
WHEN @seconds = 1 THEN '1 second ago'
ELSE 'just now'
END)
 
RETURN @LastActivity;
 
END

 

 

Khắc phục lỗi "Saving changes is not permitted" khi lưu bảng trong SQL Server

 Trong quá trình làm việc với Microsoft SQL Server Management Studio (SSMS) , đôi khi chúng ta cần thay đổi cấu trúc của 1 bảng nào đó ngay bằng giao diện đồ hoạ rất trực quan và thân thiện của SSMS. Tuy nhiên, đôi lúc chúng ta sẽ gặp phải thông báo lỗi "Saving changes is not permitted" khi chọn lưu bảng vừa thay đổi cấu trúc trong một Modal Dialog có tiêu đề là Save. Hậu quả là nỗ lực thay đổi cấu trúc chúng ta đã thực hiện trên bảng hiện tại đều bị SSMS khước từ ghi nhận.

NHẬN DẠNG LỖI "SAVING CHANGES IS NOT PERMITTED" CỦA SQL SERVER

Như đã trình bày, lỗi này xuất hiện khi chúng ta cố gắng thay đổi cấu trúc của bảng trong Microsoft SQL Server Management Studio, và cụ thể là trong những tình huống thay đổi cấu trúc bảng mà SQL Server buộc phải tạo lại bảng như:

  • Thay đổi kiểu dữ liệu của một hoặc nhiều cột trong bảng
  • Thay đổi các ràng buộc toàn vẹn NULL, NOT NULL
  • Thay đổi thứ tự của các cột trong bảng
  • Thêm cột mới vào giữa bảng
  • Xoá một hoặc nhiều cột khỏi bảng

Trong hình minh hoạ, chúng tôi đang thay đổi kiểu dữ liệu của cột b ở bảng tbtest từ kiểu dữ liệu INT thành kiểu dữ liệu NVARCHAR(50), sau thao tác này nếu chọn chức năng SAVE để lưu các thay đổi về cấu trúc lên bảng thì SSMS sẽ thông báo lỗi như sau:



NGUYÊN NHÂN GÂY RA LỖI "SAVING CHANGES IS NOT PERMITTED" TRONG SSMS CỦA SQL SERVER

Bản thân SSMS cho rằng, nếu chấp nhận thực hiện những hình thức thay đổi cấu trúc như đã liệt kê ở trên, SSMS sẽ phải yêu cầu SQL Server xoá bảng hiện tại (và các bảng có liên quan nếu có) rồi sau đó tạo lại. Như vậy, nếu không kiểm soát tốt những thay đổi cần thực hiện theo kiểu này, chúng ta có thể làm mất dữ liệu đang lưu trữ trên các bảng của hệ thống. Do đó, mặc định SQL Server bật thiết lập tuỳ chọn "ngăn chặn thao tác lưu bảng có cấu trúc bị thay đổi đến mức cần phải tạo lại bảng". 

Ngoài ra, điều cũng đáng lưu ý ở đây là Microsoft sử dụng biểu tượng cảnh báo (warning) trên hộp thoại này nhưng lại không cho chúng ta lưu lại các thay đổi trên bảng. (Điều này có vẻ không hợp lý so với cách SSMS hành xử trước đây)

CÁCH GIẢI QUYẾT LỖI "SAVING CHANGES IS NOT PERMITTED" CỦA SQL SERVER

Ngoài cách thay đổi cấu trúc bảng hiện có 1 cách nguy hiểm là xoá bảng cũ rồi tạo lại bảng mới (theo cấu trúc mới) mà SSMS mặc định khước từ thì chúng ta cũng có thể sử dụng câu lệnh SQL quen thuộc là ALTER TABLE để thay đổi cấu trúc của bảng mà không phải xoá và tạo lại bảng. Cho nên cách giải quyết thứ nhất là chuyển sang sử dụng T-SQL để thay đổi cấu trúc bảng.
Trong tình huống chúng ta vẫn muốn SSMS thực hiện các thay đổi theo kiểu re-create tables thì có thể tắt tùy chọn "Prevent saving changes that require table re-creation" trong Menu Tools/Options của SSMS ở mục Designers như hình minh hoạ



Chúc các bạn kiểm soát tốt những quyết định thay đổi cấu trúc bảng quan trọng của mình.

Tham khảo: itstudent

SQL Compact 3rd party tools

This is an attempt at a comprehensive list of SQL Server Compact Microsoft and 3rd party tools, both commercial and non-commercial. Please let me know if I have missed anything, and I will add it.

Microsoft supplied tools

SQL Server 2005 Management Studio Express SP2 (free, SQL CE 3.1)
Link: http://www.microsoft.com/en-us/download/details.aspx?id=15366

SQL Server 2008 R2 Management Studio Express (free, SQL CE 3.5 SP2)
Link: http://www.microsoft.com/en-us/download/details.aspx?id=30438

Visual Studio 2005 Standard (SQL CE 3.1)

Visual Studio 2008 Professional (SQL CE 3.5)

Visual Studio 2010 Web Developer Express with SP1 + SQL CE 4.0 Tools (free, SQL CE 3.5 SP2 + 4.0)
Link: http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express

WebMatrix (free, SQL CE 4.0)
Link: http://www.microsoft.com/web/webmatrix/

New or updated entries are noted with (new) or (updated)
”Last updated” indicates when the tool was last updated by it’s author.

Non-commercial (free) tools

My CodePlex Tools

Name: SQL Server Compact Toolbox (updated)
Link: http://sqlcetoolbox.codeplex.com/
SQL CE Versions: 3.5, 4.0
Last updated: Current
Platforms: Win32, Win64 
Added to list: 29th June 2010
”Add-in for Visual Studio 2013/2012/2010 (for 3.5 and 4.0). Standalone app (for 4.0 and 3.5)
Adds several features to help your SQL Server Compact development efforts:
- Scripting of tables, including data.
- Script of entire schema, optionally with data, both of SQL Server Compact and SQL Server 2005 or later databases, including SQL Azure.
- Import to SQL Compact 3.5 from a server database or CSV file.
- Basic, free form query execution.
- Generation of DGML files for visualizing table relationships
- Database Schema Diff Script
- Detect database file version
- Generate EDMX in any project type
- Generate Windows Phone DataContext
- Fix broken connection definitions”

Name: SqlCeScripting.dll (updated)
Link: http://exportsqlce.codeplex.com/
SQL CE Versions: 3.5, 4.0
Last updated: Current
Platforms: Win32, Win64 
Added to list: 29th June 2010
”Scripting library for inclusion in your own application, enumerates SQL Compact objects and allows scripting of these.”

Name: SqlCeCmd (updated)
Link: http://sqlcecmd.codeplex.com/
SQL CE Versions: 3.5, 4.0
Last updated: 2010
Platforms: Win32, Win64
”Administer SQL Compact databases directly from the command line, without having Visual Studio or SQL Server Management Studio installed. Only requires NetFx 2.0 and SQL Compact installed. Command line options similar to sqlcmd. Runs scripts generated by ExportSqlCe.”

Name: ExportSqlCe (updated)
Link: http://exportsqlce.codeplex.com/
SQL CE Versions: 3.0, 3.5, 4.0
Last updated: Current
Platforms: Win32, Win64 
”This command line utility helps you better manage your SQL Compact development efforts. If allows you to script schema and data from any SQL Compact database file to a .sql file, which can be used in any context. The utility is developed in C# with Visual Studio 2008. You can use the resulting script for documentation, programmatic scripting of SQL Compact database files, or migration of schema and data to SQL Server (Express) 2005 or later.

Name: Export2SqlCe (updated)
Link: http://exportsqlce.codeplex.com/
SQL Server Versions: 2005, 2008 
Last updated: Current
Platforms: Win32
Added to list: 4th March 2010
”A command line utility to script an entire SQL Server 2005 or later database with or without data to a SQL Compact T-SQL script.”

Name: ExportSqlCe SSMS 2008 Addin
Link: http://exportsqlce.codeplex.com/
SQL CE Versions: 3.5
Last updated: 2012
Platforms: Win32
”Script database/table schema/data and also DML  (SELECT, INSERT, UPDATE, DELETE) directly from the Object Explorer in SQL Server 2008 Management Studio (Express). In addition, Edit table data, Import data from as CSV file and Rename the table.”

Name: SqlCeBulkCopy (updated) 
Link: http://sqlcebulkcopy.codeplex.com/
SQL CE Versions: 3.5, 4.0
Last updated: Current 
Platforms: .NET library, .NET CF library 
Added to list: 4th March 2010 
”.NET Library for loading data fast (doing bulk inserts) into a SQL Server Compact database file. Attempts to mimic the SQLClient SqlBulkCopy API. Includes support for BULK INSERTing any IEnumerable”

Query and database management tools

Name: Data Port Console
Link: http://primeworks-mobile.blogspot.dk/2013/09/data-port-console-is-now-free.html
SQL CE Versions: 2.0, 3.0, 3.5, 4.0
Last updated: 2012
Platforms: Windows CE, Win32
”Manage all your SQL Compact Edition databases from one central location with the new Data Port Console.”

Name: Data Port Wizard
Link: http://primeworks-mobile.blogspot.dk/2013/09/data-port-wizard-is-now-free.html
SQL CE Versions: 2.0, 3.0, 3.5, 4.0
Last updated: 2011
Platforms: Windows CE, Win32
”Quickly and easily transfer databases from the desktop to the Mobile Device and back. Data Port Wizard will make full copies of your Microsoft Access or Microsoft SQL Server databases into SQL Server Compact Edition 3.5 and 3.0, and SQL CE 2.0 databases - and back.”

Name: CompactView
Link: http://sourceforge.net/p/compactview/home/Home/
SQL CE Versions: 3.1, 3.5, 4.0
Last updated: 2012
Platforms: Win32, Win64
Added to list: 14th November 2011
CompactView is a viewer for Microsoft® SQL Server® Compact Edition (SQLCE) database files (*.sdf). CompactView can open database files of versions 3.1, 3.5 and 4.0

Name: SQL Compact Query Analyzer
Link: http://sqlcequery.codeplex.com/
SQL CE Versions: 3.1, 3.5, 4.0
Last updated: 2012
Platforms: Win32, Win64
Added to list: 3rd July 2011 
Features:
- Execute SQL Queries against a SQL Server Compact Edition database
- Table Data Editor to easily edit the contents of the database
- Supports SQLCE 3.0, 3.1, 3.5 and 4.0
- Execute multiple SQL queries (delimited by a semi colon ;)
- Display query result as XML
- Shrink and Compact Databases


- Generate Schema and Data Scripts
- Display database and schema information

Name: LINQPad
Link: http://www.linqpad.net/
SQL CE Versions: 3.5, 4.0
Last updated: Current
Platforms: Win32, Win64
Added to list: 14th December 2010
Linqpad allows you to query various data sources via LINQ, including SQL Server Compact 3.5 and 4.0. See this blog post.

Name: Database .NET
Link: http://fishcodelib.com/Database.htm
SQL CE Versions: 3.1, 3.5, 4.0
Last updated: Current
Platforms: Win32, Win64
Added to list: 20th September 2010
“Database .NET is a simple and intuitive database management tool for multiple databases. Making Local and Remote Database Administration Easier, With it you can Create databases, Design tables, Edit data, Export data, Generate scripts and run SQL queries.”

Name: SQL CE Browser
Link: http://ericwillis.com/notes/2009/12/sql-ce-browser-v-110/
SQL CE Versions: 3.5
Last updated: 2010
Platforms: Win32, Win64 (?)
Added to list: 4th March 2010 
”Open regular and encrypted/passworded databases for viewing or editing. Write and work with any number of queries at once via tabs. SQL syntax highlighting and SQL syntax verification. Explore columns, keys, and indexes“

Name: Mini SQL Query
Link: http://minisqlquery.codeplex.com/ 
SQL CE Versions: 3.5
Last updated: 2012
Platforms: Win32, Win64 (?)
Added to list: 4th March 2010 
”Mini SQL Query is a minimalist SQL query tool for multiple databases (MSSQL, MSSQL CE, SQLite, OLEDB, MS Access/Excel files etc). The tool uses a generic schema engine taking advantage of the ADO.NET providers. Mini SQL Query is also easily extended with plugins.“

Name: SQL Server CE Query Tool
Link: http://cequery.codeplex.com
SQL CE Versions: 3.5, 4.0
Last updated: 2011 
Platforms: Win32, Win64 (?)
CEQuery is written in C# with the help of Visual Studio 2008 platform. Some of the features of this tool are described below:
User is able to create CE database. If the schema is provided, the tool is able to create the tables and columns. User is able to overview an existing CE database with its table and column structure in tree format. User can design a query by dragging and dropping tables and columns from the database tree. User can manipulate [Insert/Update/Delete] records in a selected table. User is able to generate scripts from a single table or of whole databases. [Both for SQL CE or SQL Server]. User is able to open multiple SQL Server CE files simultaneously. User is able to convert a SQL Server database to a SDF file with schema and data. User is able to change password of a SQL CE DB. The tool is now capable of handling the database with no password.“

Name: SeasonStar Database Management(SSDM)
Link: http://ssdm.codeplex.com/
SQL CE Versions: 3.5?, 4.0 
Last updated: 2011
Platforms: Win32
”With support for all major database formats, top-class export functions and advanced feaures like Linq Data Context availabe, SSDM is probably your best choice for DB management. It's even free software!”

Name: SQL CE Database Editor
Link: http://sqlcedatabaseeditor.codeplex.com/
SQL CE Versions: 3.5
Last updated: 2009 
Platforms: Win32
“Small lightweight application to browse and edit Microsoft SQL CE server databases. Does not require SQL CE server to be installed and can run custom queries.”

Name: DataBoy
Link:http://databoy.codeplex.com/
SQL CE Versions: 3.0, 3.5
Last updated: 2008
Platforms: Win32
“Small footprint, portable and simple database query tool. Support SQL CE 3.1, SQL CE 3.5 and SQL Server.”

Other tools and libraries

Name: SQLite2CE
Link: http://sqlite2ce.codeplex.com/
SQL CE Versions: 3.5
Last updated: 2012
Platforms: Win32, Win64
Added to list: 14th November, 2011 
“A tool that converts a SQLite database into SQL CE while simultaneously creating the default data representation classes needed to easily incorporate the new database into your Windows Phone application. The tool migrates the Schema, Table Data, and Views ( but not triggers). The tool handles the differences in data types and does an appropriate migration that is configurable in the settings.xml.”

Name: SQLCE SCRIPTER
Link: http://sqlmgmt.com/sql/SQLCE-Scripter
SQL CE Versions: 3.5, 4.0
Last updated: 2011
Platforms: Win32, Win64
Added to list: 14th November, 2011
“Create SQL schema scripts for tables, indexes and referential relations. Create data scripts so that CE data can be moved to SQL Server or other data store. User can select specific tables only. User can select Script Schema, Script Data or both.”

Name: SQLCE Code Generator
Link: http://sqlcecodegen.codeplex.com/
SQL CE Versions: 3.5, 4.0
Last updated: 2012 
Platforms: Win32, Win64
Added to list: 27th March, 2011
“Contains a stand alone GUI application and a Visual Studio Custom Tool for automatically generating a .NET data access layer code with Unit tests for objects in a SQL Server Compact Edition database. Also generates a Windows Phone DataContext”

Name: OpenNETCF.ORM Framework
Link: http://orm.codeplex.com/
SQL CE Versions: 3.5
Last updated: Current 
Platforms: WinCE, Win32, Win64
Added to list: 27th March, 2011
“The OpenNETCF.ORM library is a lightweight object-relational mapping framework designed for use with the .NET Compact Framework.The framework is extensible to allow any type of backing store. An initial implementation using SQL Server Compact is provided.”

Name: SQL Metal Open Source User Interface
Link: http://sqlmetalosui.codeplex.com/
SQL CE Versions: 3.5
Last updated: 2008 
Platforms: Win32
“This project provides an user interface for SqlMetal.exe tool.
SQLMetalOSUI allows users to generate code and mapping files for their SQL Server Compact Edition databases. SQL Server Compact Edition 3.5 is fully compatible with LINQ to SQL but the designer does not. This project will be focused to reach this initial purpose.”

Commercial tools


Name: MS Compact Maestro (new)
Link: http://www.sqlmaestro.com/products/mssql/compactmaestro/ 
SQL CE Versions: 3.5, 4.0
Last updated: 2013
Platforms: Win32, Win64
”MS Compact Maestro is a top-class SQL Server Compact management and development tool.”

Name: SQLCE Database Viewer
Link: http://www.pocketpctoolkit.com/index.php
SQL CE Versions: 2.0, 3.0, 3.5
Last updated: 2007
Platforms: Windows CE, Win32
The easiest way to view and edit your device's SQLCE databases, directly on your Desktop ! View and edit the tables, columns and data in your device's SQLCE 2.0 and SQL Server Mobile, and SQLCE Compact Edition v3.5 tables. Export their data structures (and data) into any ODBC data source. View and edit your device's registry entries & processes. Built-in file explorer - the easiest way to view, open and execute the files on your device.”

Name: SDF Viewer 
Link: http://www.flyhoward.com/SDF
Viewer.aspx
SQL CE Versions: 3.0, 3.5, 4.0
Last updated: Current
Platforms: Win32
“The simple way to create, view, edit or export the data in your Windows Mobile or Pocket PC device's SQLCE database, from the convenience of your Desktop. Run SQL commands on your SQLCE databases, and view the results instantly.”

Name: RemoteSqlCe
Link: http://www.gui-innovations.com/html/remotesqlce.html
SQL CE Versions: 2.0, 3.0
Last updated: 2007
Platforms: Windows CE, Win32
”SqlServerCE is a great database for Pocket PC’s, but designing, maintaining and querying databases on the PPC, especially whilst developing, can be wearing. We developed this tool to help us when developing for SqlServerCE. With RemoteSQLCe you can completely manage your SqlServerCE database from the desktop. RemoteSQLCE works in the cradle, and over ethernet/bluetooth.”