sqlite與sqlserver區別

一、查詢時把兩個字段拼接在一塊兒sql

--sqlserver--
select Filed1+'@'+Filed2 from table

--sqlite--
select Filed1||'@'||Filed2 from table


二、使用腳本添加字段,更改字段類型,刪除字段sqlserver

--------添加字段----------

--sqlserver--
IF not exists 
    (select * from syscolumns where id=object_id('表名') and name='字段')
BEGIN
    alter table 表名 add 字段 int
end

--sqlite--
alter table 表名 add 字段 int


--------更改字段類型----------

--sqlserver--
alter table table alter column filed nvarchar(256)

--sqlite中須要把舊錶重命名,建立新表(這個時候更改字段類型),而後再把數據導入到新表中,刪除舊錶--
ALTER TABLE  表名  RENAME TO "重命名"

Create TABLE "表名"(
[Id] bigint NOT NULL
,[Name] nvarchar(16) 
, Primary Key(Id)   
)

Insert Into '重命名' ([Id],[Name])  Select [Id],[Name] From MAIN.['表名']

Drop Table MAIN.[重命名錶]

 三、取前幾條數據spa

  

--sqlsever--
SELECT TOP 10 * FROM table ORDER BY filed DESC

--sqlite--
select * from table limit 0,10

四、判斷插入數據
  code

  

--sqlserver--
IF NOT EXISTS (select * from table where FID=6)  
BEGIN 
insert into table(FName,FIsDelete) select 't',0 
END

--sqlite--
insert into table(FName,FIsDelete)
select 'tt',0 where not exists(
select * from table where FID=6
)
相關文章
相關標籤/搜索