1.waitfor
--例 等待1 小時2 分零3 秒後才執行select 語句
waitfor delay '01:02:03'
select * from employee
--例 等到晚上11 點零8 分後才執行select 語句
waitfor time '23:08:00'
select * from employee
2.檢視sqlserver版本
select serverproperty('productversion'),serverproperty('productlevel'),serverproperty('edition')
5.sql語句附加資料庫
use master
exec sp_attach_db @dbname = n'pubs',
@filename1 = n'c:\program files\microsoft sql server\mssql\data\pubs.mdf',
@filename2 = n'c:\program files\microsoft sql server\mssql\data\pubs_log.ldf'
6.資料庫表間資料複製
--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 (前五條紀錄)
7.按姓氏筆畫排序
Sql語句收藏
1 查詢列表,按照in的排序進行排序 code select select count 0 from picture where album id album id aspiccount from album where id in 5 6,8 1,3 4 order bycharindex ltr...
幾個很有用的SQL語句
1 獲取某個資料庫所有表的資料行數 select o.name,i.rowcnt from sysobjects o join sysindexes i on o.id i.id where o.type u and i.indid 1 and o.name dtproperties order b...
幾個很有用的SQL語句
1 獲取某個資料庫所有表的資料行數 select o.name,i.rowcnt from sysobjects o join sysindexes i on o.id i.id where o.type u and i.indid 1 and o.name dtproperties order b...