Have you ever encountered any of these differences between SQLite and SQL? I have summarized some of the differences that often occur between SQLite and SQL. I hope this will be helpful to you.
I. Summary of Common Problems
1 top
This is a frequently asked question. For example, you can use the following statement in sqlserver to obtain the first 10 records in the record set:
[Pre]
Select
Top10 *
From[
Index]
Order
ByIndexid
Desc;
[/PRE] but this SQL statement cannot be executed in SQLite. It should be changed:
[Pre]
Select*
From[
Index]
Order
ByIndexid
DescLimit 0, 10;
[/PRE] Here, limit 0th indicates that 10 records are read from records.
2. Create View)
SQLite has a bug when creating a multi-Table view. The problem is as follows:
[Pre]
Create
ViewWatch_single
As
SelectDistinctwatch_item. [watchid], watch_item. [Itemid]
FromWatch_item;
[/PRE] After the preceding SQL statement is executed, it is displayed as successful,
[Pre]
Select Count(*)
From[Watch_single]
WhereWatch _ single. watchid = 1;
[/PRE] Other statements cannot be executed. The reason is that the table name of the field is specified when the view is created, and SQLite cannot identify it correctly. Therefore, the above statement should be changed:
[Pre]
Create
ViewWatch_single
As
Select
Distinct[Watchid], [Itemid]
FromWatch_item;
[/PRE] But the question that arises is what if a multi-Table view has a duplicate Name field between tables?
3 count (distinct column)
SQLite reports an error when executing the following statement:
[Pre]
Select Count(
DistinctWatchid)
From[Watch_item]
WhereWatch_item.watchid = 1;
[/PRE] the reason is that all built-in functions of SQLite do not support distinct limitation, so it may be difficult to count the number of records that are not repeated. It is feasible to create a view of the record table that does not repeat, and then count the view.
4 external connections
Although SQLite officially claims that left Outer Join has been implemented, there is no right Outer Join or full outer join. However, the actual test shows that it does not seem to work properly. When executing the following three statements, an error is reported:
[Pre]
Select Tags. [tagid]
From [Tags], [tag_rss]
Where Tags. [tagid] = tag_rss. [tagid] (*);
-
- SelectTags. [tagid]From[Tags], [tag_rss]Where Left Outer JoinTag_rss. [tagid] = tags. [tagid];
SelectTags. [tagid]From[Tags], [tag_rss]Where Left JoinTag_rss. [tagid] = tags. [tagid];
[/PRE] In addition, it is not feasible to replace "*" with "+.
2. Collect the syntax differences between SQLite and SQL Server
1. Return the last inserted id value
Returns the last inserted id value. @ identity is used by SQL Server.
SQLite uses the scalar function last_insert_rowid ()
Returns the row identifier (generated primary key) of the last row inserted to the database through the current sqlconnection ). This value is the same as the value returned by the sqlconnection. lastinsertrowid attribute.
2. Top N
In SQL Server, the first two rows can be returned as follows:
[Pre]
Select
Top2 *
FromAA
- Order ByIDSDesc
[/PRE] limit is used in SQLite. The statement is as follows:
[Pre]
Select*
FromAA
- Order ByIDSDesc
Limit 2
[/PRE] 3. getdate ()
in SQL Server, getdate () returns the current system Date and Time.
SQLite does not exist.
4. exists statement
SQL Server determines insertion (insert if IDs = 5 does not exist)
[pre]
If NotExists (
Select*
FromAA
WhereIDS = 5)
- Begin
Insert IntoAA (nickname)
- Select 'T'
End
[/PRE] this can be done in SQLite
[Pre]
insert
into AA (nickname)
- select 'T'
where not exists ( select * from AA where IDs = 5)
[/PRE] 5. nested transactions
SQLite only allows transactions of a single activity
6. right and full outer join
SQLite does not support right Outer Join or full outer join
7. updatable view
SQLite view is read-only. You cannot execute Delete, insert, or update statements on a view, SQL Server can delete, insert, or update views.
3. New content
1. default settings for date and time columns:
the "column" setting includes three fields: name, type, and default
Name: logtime (randomly named);
type:
date type. The value is like ",
'datetime' type. The obtained value is like "11:49:04. 000 ";
default: datetime ('now ', 'localtime') I use two parameters. Do not discard the subsequent localtime, otherwise, the time is inaccurate.