Document directory
- 3 count (distinct column)
- 4 external connections
- 5 Foreign keys
- 1. Return the last inserted id value
- 2. Top N
- 3. getdate ()
- 4. exists statement
- 5. nested transactions
- 6. Right and full outer join
- 7. updatable views
Summary of top 1 SQL syntaxes not supported by SQLite
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:
Select top 10 * from [Index] order by indexid DESC;
However, this SQL statement cannot be executed in SQLite. It should be changed:
Select * from [Index] order by indexid DESC limit 0, 10;
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:
Create view watch_single as select distinctwatch_item. [watchid], watch_item. [Itemid] From watch_item;
After the preceding SQL statement is executed, it is displayed as successful.
Select count (*) from [watch_single] Where watch _ single. watchid = 1;
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:
Create view watch_single as select distinct [watchid], [itemid] FROM watch_item;
However, what should I do 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:
Select count (DISTINCT watchid) FROM [watch_item] WHERE watch_item.watchid = 1;
The reason is that all built-in functions of SQLite do not support DISTINCT limitation. Therefore, it is troublesome 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:
SELECT tags. [tagid] FROM [tags], [tag_rss] WHERE tags. [tagid] = tag_rss. [tagid] (*);
SELECT tags. [tagid] FROM [tags], [tag_rss] where left outer join tag_rss. [tagid] = tags. [tagid];
SELECT tags. [tagid] FROM [tags], [tag_rss] where left join tag_rss. [tagid] = tags. [tagid];
In addition, it is not feasible to replace "*" with "+.
5 Foreign keys
SQLite supports foreign keys only after version 3.6
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:
Select Top 2 * from AA
Order by IDS DESC
Use Limit in SQLite. The statement is as follows:
Select * from AA
Order by IDS DESC
Limit 2
3. getdate ()
Getdate () in SQL Server Returns the current system date and time
Not in SQLite
4. exists statement
Insert data in SQL Server (insert data if IDs = 5 does not exist)
If not exists (select * from AA where IDs = 5)
Begin
Insert into AA (nickname)
Select 'T'
End
This can be done in SQLite.
Insert into AA (nickname)
Select 'T'
Where not exists (select * from AA where IDs = 5)
5. nested transactions
SQLite only allows a single active transaction
6. Right and full outer join
SQLite does not support right Outer Join or full outer join.
7. updatable views
The SQLite view is read-only. You cannot execute Delete, insert, or update statements on a view. SQL server can delete, insert, or update a view.