数据库表间数据复制
--1.表结构相同的表,且在同一数据库(如,table1,table2)

Sql :insert into table1 select * from table2 (完全复制)

insert into table1 select distinct * from table2(不复制重复纪录)

insert into table1 select top 5 * from table2 (前五条纪录)

--2.不在同一数据库中(如,db1 table1,db2 table2)

sql: insert into db1..table1 select * from db2..table2 (完全复制)

insert into db1..table1 select distinct * from db2table2(不复制重复纪录)

insert into tdb1..able1 select top 5 * from db2table2 (前五条纪录)
select top 1 RandomNum from Rand order by NewID()
select cast( floor(rand()*N) as int)
--产生0到N-1之间的随机数
select cast(ceiling(rand() * N) as int)
--产生1到N之间的随机数
CONVERT(VARCHAR(10),GETDATE(),120)
--返回2008-04-12
CONVERT(VARCHAR(10),GETDATE(),20)
--返回2008-04-12
CONVERT(VARCHAR(10),GETDATE(),112)
--返回20080412
CONVERT(VARCHAR(10),GETDATE(),111)
--返回2008/04/12















sqlserver中取随机数的两种方法
a.创建一个表Rand,字段是:RandomNum ,存储0到9的数据。
使用下面SQL语句可产生随机数:


b.使用sqlserver提供的Rand()函数




在数据库中几个常用的日期格式转换
日期格式转换也是经常用到的,通常2008-04-12和20080412 这两种格式用的比较多,下面列出一些常用的:







