where 1=1的写法是为了检化程序中对条件的检测
打个比方有三个参数a, b, c
@sql=select * from tb'
这三个参数都可能为空
这时你要构造语句的话,一个个检测再写语句就麻烦
比如
if @a is not null
@sql=@sql + " where a=' + @a
if @b is not null
这里你怎么写?要不要加where 或直接用 and ?,你这里还要对@a是否为空进行检测
用上 where 1=1 之后,就不存在这样的问题, 条件是 and 就直接and ,是or就直接接 or
拷贝表 create table_name as select * from Source_table where 1=1;
复制表结构 create table_name as select * from Source_table where 1 <> 1;