1、複製表(包括表結構、表資料)
sqlserver:
select * into user_copy from user
mysql:
create table user_copy like user;
insert into user_copy select * from user;
2、多表連線做update
sqlserver:
update s1 set s1.salary= s2.salary
from (select * from s where age>10) as s1 join s2 on s1.uname= s2.uname
where s1.uname = 'xx'
mysql:(無法直接對目標表的查詢資料直接做更新,只能針對目標表操作)
update s1 join s2 on s1.uname= s2.uname
set s1.salary= s2.salary
where s1.uname = 'xx'
3、修改表字段結構
sqlserver:
alter table user alter column uid int not null
goalter table user alter column name nvarchar(100) not null
gomysql:(無法直接對目標表的查詢資料直接做更新,只能針對目標表操作)
alter table user modify uid int not null comment 'xx';
alter table user modify name varchar(100) not null comment 'xxy';
4、新增、修改主鍵
sqlserver:
alter table user add constraint pk_uid_name primary key(uid, name)
mysql:(無法直接對目標表的查詢資料直接做更新,只能針對目標表操作)
alter table user drop primary key;
alter table user add primary key (uid, name);
5、查詢資料拼接sql語句
sqlserver:
select 'insert into dbo.tablename([id],[name]) values ('+ cast([id] as varchar) + ',''' + cast([name] as varchar) + ''')'
from dbo.tablename where id > 433
6、查詢字段首位為漢字
sqlserver:
select * from 表名 where ascii(字段)>127
7、查詢字段包含漢字(任意位)
sqlserver:
select * from 表名 where 字段 like '%[吖-座]%'--[吖-座]是中文字符集第乙個到最後乙個的範圍
8、sqlserver和mysql插入記錄前判斷是否存在,存在則插入,不存在則修改
sqlserver:
if not exists(select * from setting where id=0)insert into setting(id,title,searchkeys, serviceintervalsecond,sleepmillisecondpersearch) values(0,@title,@searchkeys,@serviceintervalsecond,@sleepmillisecondpersearch)
else
update setting set title=@title,searchkeys=@searchkeys,serviceintervalsecond=@serviceintervalsecond, sleepmillisecondpersearch=@sleepmillisecondpersearch
mysql:
insert into `his_examine_result` (mid,his_examine_mid, his_file_mid, resulttype, his_employee_mid,his_employee_name, examineresult, examineitemname, examinestandardname,
examineitemunit, examinehighvalue, examinelowvalue, examinediscription, discription)
values ($mid,$examinemid,$filemid,1,null,null,'',$itemname,$standname,$itemunit,$highvalue,$lowvalue,'','')
on duplicate key update examineresult=$result,examinediscription=$dis
9、建立索引
sqlserver:
if not exists(select * from sysindexes where id = object_id('t_person_info') and name = 'idx_pcode')
create nonclustered index idx_pcode on [dbo].t_person_info
(pcode asc
) on [primary];
sql server與mysql差異收集
之後會陸續收集,先寫一點 sql server中的identity在mysql中的表現形式。mysql中沒有identity 函式,要設定自動編號的話應當是用 auto increment 例如 create table tbl topic topicid int not null auto inc...
MySql與SqlServer的區別
1.sql server 是microsoft 公司推出的關係型資料庫管理系統。具有使用方便可伸縮性好與相關軟體整合程度高等優點,可跨越從執行microsoft windows 98 的膝上型電腦到執行microsoft windows 2012 的大型多處理器的伺服器等多種平台使用。microso...
SQLServer與MySQL的優缺點
mysql 效能更好,價錢更低 優點分析 mysql短小精悍,容易上手,操作簡單,免費供用的。相對其它資料庫有特色又實用的語法多一些。sql怎麼也算是大型資料庫,穩定,能做一般大系統的資料倉儲,執行速度明顯比mysql快n多 海量資料下這個優勢顯而易見 缺點分析 mysql難擔當大系統的資料倉儲,執...