<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:georss="http://www.georss.org/georss" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Static Void - SqlServerCe</title>
    <link>http://martinwilley.com/blog/</link>
    <description>What next?</description>
    <language>en-us</language>
    <copyright>Martin Willey</copyright>
    <lastBuildDate>Mon, 25 Apr 2011 10:13:17 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>me@martinwilley.com</managingEditor>
    <webMaster>me@martinwilley.com</webMaster>
    <item>
      <trackback:ping>http://martinwilley.com/blog/Trackback.aspx?guid=2374a274-7c2e-49a4-808f-8b33799b4fe3</trackback:ping>
      <pingback:server>http://martinwilley.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://martinwilley.com/blog/PermaLink,guid,2374a274-7c2e-49a4-808f-8b33799b4fe3.aspx</pingback:target>
      <dc:creator>Martin</dc:creator>
      <wfw:comment>http://martinwilley.com/blog/CommentView,guid,2374a274-7c2e-49a4-808f-8b33799b4fe3.aspx</wfw:comment>
      <wfw:commentRss>http://martinwilley.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=2374a274-7c2e-49a4-808f-8b33799b4fe3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Shortly after the last release of <a href="http://dbschemareader.codeplex.com/" target="_blank">Database
Schema Reader</a>, here's another release.
</p>
        <p>
          <a href="http://martinwilley.com/blog/2011/04/09/DatabaseSchemaReaderNowWithExtraSQLite.aspx" target="_blank">Last
time</a> I added a CopyToSQLite tool, which reads (almost) any database and creates
a SQLite clone. I also added experimental support for SQLServer CE 4.0, but it had
some big limitations. 
</p>
        <p>
So the obvious next step was to fix some of those limitations, and that's what this
release focuses on. Unfortunately CopyToSQLite.exe is now a little misnamed. <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://www.martinwilley.com/blog/content/binary/Database-Schema-Reader-with-more-.0-love_9CD7/wlEmoticon-winkingsmile.png" /></p>
        <p>
I added a little bit of conversion code so VARCHAR(MAX) found in the origin database
gets converted to NTEXT (and VARBINARY to IMAGE). The reading of SQLServer CE 4 databases
got improved too (capturing the  foreign and unique keys and identity columns).
</p>
        <p>
SQLServer allows an integer column to be marked as "Identity" so it will be auto-generated
(the equivalent in Oracle is to create a sequence and an insert trigger). But you
can't include the identity column when you insert a row. So, when cloning data, SQLServer
also allows identity-inserts with SET IDENTITY_INSERT [MyTable] ON/OFF. When you've
done that, you should reset the identity seed with DBCC CHECKIDENT.
</p>
        <p>
But in SQLServer CE 4, there is no DBCC CHECKIDENT. You have to do an ALTER TABLE
[MyTable] ALTER COLUMN [IdentityColumn] IDENTITY (999,1) (where 999 is the new max(IdentityColumn)).
It's another of those little gotchas between SQLServer and SQLServer CE.
</p>
        <p>
SQLServer CE 4 has some great new paging syntax:
</p>
        <p>
SELECT Id, Name FROM MyTable 
<br />
ORDER BY Name 
<br />
OFFSET 10 ROWS 
<br />
FETCH NEXT 5 ROWS ONLY
</p>
        <p>
It's similar to the LIMIT/OFFSET syntax in MySQL and SQLite, but (reasonably enough)
must follow an ORDER BY. Rather than offset/skipping a number of rows, I'd like to
specify just page number and page size - or another formula. The <a href="http://msdn.microsoft.com/en-us/library/ms188385%28v=sql.110%29.aspx#Offset" target="_blank">SQLServer
2011/Denali documentation</a> shows the offset/fetch syntax for a start row/end row
expression:
</p>
        <p>
SELECT DepartmentID, Name, GroupName 
<br />
FROM HumanResources.Department 
<br />
ORDER BY DepartmentID ASC 
<br />
OFFSET @StartingRowNumber - 1 ROWS 
<br />
FETCH NEXT @EndingRowNumber - @StartingRowNumber + 1 ROWS ONLY
</p>
        <p>
But that doesn't work in SQLServer CE 4. You can use parameters, or constants, or
expressions with constants, but apparently not expressions with constants and parameters.
Oh well, it's still much better than horrible OVER subqueries.<br /></p>
        <p>
Overall, the "CopyToSQLite" to SQLServer CE 4 seems to work well. Using easily deployable
file databases like SQLServer CE and SQLite is simple and powerful. 
</p>
        <img width="0" height="0" src="http://martinwilley.com/blog/aggbug.ashx?id=2374a274-7c2e-49a4-808f-8b33799b4fe3" />
      </body>
      <title>Database Schema Reader with more SqlServerCE 4.0 love</title>
      <guid isPermaLink="false">http://martinwilley.com/blog/PermaLink,guid,2374a274-7c2e-49a4-808f-8b33799b4fe3.aspx</guid>
      <link>http://martinwilley.com/blog/2011/04/25/DatabaseSchemaReaderWithMoreSqlServerCE40Love.aspx</link>
      <pubDate>Mon, 25 Apr 2011 10:13:17 GMT</pubDate>
      <description>&lt;p&gt;
Shortly after the last release of &lt;a href="http://dbschemareader.codeplex.com/" target="_blank"&gt;Database
Schema Reader&lt;/a&gt;, here's another release.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://martinwilley.com/blog/2011/04/09/DatabaseSchemaReaderNowWithExtraSQLite.aspx" target="_blank"&gt;Last
time&lt;/a&gt; I added a CopyToSQLite tool, which reads (almost) any database and creates
a SQLite clone. I also added experimental support for SQLServer CE 4.0, but it had
some big limitations. 
&lt;/p&gt;
&lt;p&gt;
So the obvious next step was to fix some of those limitations, and that's what this
release focuses on. Unfortunately CopyToSQLite.exe is now a little misnamed. &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://www.martinwilley.com/blog/content/binary/Database-Schema-Reader-with-more-.0-love_9CD7/wlEmoticon-winkingsmile.png"&gt;
&lt;/p&gt;
&lt;p&gt;
I added a little bit of conversion code so VARCHAR(MAX) found in the origin database
gets converted to NTEXT (and VARBINARY to IMAGE). The reading of SQLServer CE 4 databases
got improved too (capturing the&amp;nbsp; foreign and unique keys and identity columns).
&lt;/p&gt;
&lt;p&gt;
SQLServer allows an integer column to be marked as "Identity" so it will be auto-generated
(the equivalent in Oracle is to create a sequence and an insert trigger). But you
can't include the identity column when you insert a row. So, when cloning data, SQLServer
also allows identity-inserts with SET IDENTITY_INSERT [MyTable] ON/OFF. When you've
done that, you should reset the identity seed with DBCC CHECKIDENT.
&lt;/p&gt;
&lt;p&gt;
But in SQLServer CE 4, there is no DBCC CHECKIDENT. You have to do an ALTER TABLE
[MyTable] ALTER COLUMN [IdentityColumn] IDENTITY (999,1) (where 999 is the new max(IdentityColumn)).
It's another of those little gotchas between SQLServer and SQLServer CE.
&lt;/p&gt;
&lt;p&gt;
SQLServer CE 4 has some great new paging syntax:
&lt;/p&gt;
&lt;p&gt;
SELECT Id, Name FROM MyTable 
&lt;br&gt;
ORDER BY Name 
&lt;br&gt;
OFFSET 10 ROWS 
&lt;br&gt;
FETCH NEXT 5 ROWS ONLY
&lt;/p&gt;
&lt;p&gt;
It's similar to the LIMIT/OFFSET syntax in MySQL and SQLite, but (reasonably enough)
must follow an ORDER BY. Rather than offset/skipping a number of rows, I'd like to
specify just page number and page size - or another formula. The &lt;a href="http://msdn.microsoft.com/en-us/library/ms188385%28v=sql.110%29.aspx#Offset" target="_blank"&gt;SQLServer
2011/Denali documentation&lt;/a&gt; shows the offset/fetch syntax for a start row/end row
expression:
&lt;/p&gt;
&lt;p&gt;
SELECT DepartmentID, Name, GroupName 
&lt;br&gt;
FROM HumanResources.Department 
&lt;br&gt;
ORDER BY DepartmentID ASC 
&lt;br&gt;
OFFSET @StartingRowNumber - 1 ROWS 
&lt;br&gt;
FETCH NEXT @EndingRowNumber - @StartingRowNumber + 1 ROWS ONLY
&lt;/p&gt;
&lt;p&gt;
But that doesn't work in SQLServer CE 4. You can use parameters, or constants, or
expressions with constants, but apparently not expressions with constants and parameters.
Oh well, it's still much better than horrible OVER subqueries.&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
Overall, the "CopyToSQLite" to SQLServer CE 4 seems to work well. Using easily deployable
file databases like SQLServer CE and SQLite is simple and powerful. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://martinwilley.com/blog/aggbug.ashx?id=2374a274-7c2e-49a4-808f-8b33799b4fe3" /&gt;</description>
      <comments>http://martinwilley.com/blog/CommentView,guid,2374a274-7c2e-49a4-808f-8b33799b4fe3.aspx</comments>
      <category>Codeplex</category>
      <category>Database Schema Reader</category>
      <category>SqlServerCe</category>
    </item>
  </channel>
</rss>