查询:
-----时间的转换日、周、
--查询当前是今年第几周后面
select (@@datefirst+datepart(dw,getdate())-1)
--加上%7 后就是当前是星期几
select (select (@@datefirst+datepart(dw,getdate())-1)%7)
--前一天的时间查询
select getdate()
SELECT DATEADD(day, -1, LEFT(getdate(), 10))
SELECT DATEADD(day, -1, LEFT(convert(datetime,'2013-03-07 15:25:26'), 10))
SELECT DATEADD(day, -1, convert(datetime,'2013-03-07 15:25:26'))
--DATEADD(datepart,number,date)函数在日期中添加或减去指定的时间间隔
-- -1是指定查询datepart减一
------查询添加
INSERT INTO SELECT
语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Table1
一个表向另一个表添加数据,当另一个表不存在时,
select * into test from parsed_msg
-----XML临时表 加insert into select
1 DECLARE @idoc int 2 DECLARE @doc varchar(1000) 3 SET @doc =N'<?xml version="1.0"?> 4 <ArrayOfT_pro_GoodsAttribute xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 5 <t_pro_GoodsAttribute> 6 <GoodsAttributeID>0</GoodsAttributeID> 7 <GoodsID>011f4fe9-4b0f-4ac7-8b45-eed8798dd767</GoodsID> 8 <AttributeID>3</AttributeID> 9 <Item_SelectedValue>23</Item_SelectedValue> 10 <Item_InputtedValue_Text>16.80</Item_InputtedValue_Text> 11 </t_pro_GoodsAttribute> 12 </ArrayOfT_pro_GoodsAttribute>'; 13 --Create an internal representation of the XML document. 14 EXEC sp_xml_preparedocument @idoc OUTPUT, @doc 15 -- Execute a SELECT statement that uses the OPENXML rowset provider. 16 insert into ts_pro_GoodsAttribute(GoodsID,AttributeID,Item_SelectedValue,Item_InputtedValue_Text) 17 SELECT * 18 FROM OPENXML (@idoc, '/ArrayOfT_pro_GoodsAttribute/t_pro_GoodsAttribute',1) 19 WITH ( 20 GoodsID uniqueidentifier 'GoodsID', 21 AttributeID int 'AttributeID', 22 Item_SelectedValue int 'Item_SelectedValue', 23 Item_InputtedValue varchar(20) 'Item_InputtedValue_Text' 24 )
-----修改列的大小
ALTER TABLE searched_msg ALTER COLUMN sm_client varchar(500)
------- 快删除表内容
truncate table searched_msg
------压缩数据
dbcc shrinkdatabase(RostDataAnalyseDB)
索引
-----创建索引
create clustered index riqi_person on person(date)
------在person表的date字段上面创建名为riqi_person的【聚集索引】
create nonclustered index riqi_person on person(date)
------在person表的date字段上面创建名为riqi_person的【非聚集索引】
create clustered index date_person on person(date,id)
------在person表的date,age字段上面创建名为riqi_person的【复合聚集索引】
create nonclustered index date_person on person(date,age)
------在person表的date,age字段上面创建名为riqi_person的【复合非聚集索引】
-----查看索引create clustered index riqi_person on person(date)
------在person表的date字段上面创建名为riqi_person的【聚集索引】
create nonclustered index riqi_person on person(date)
------在person表的date字段上面创建名为riqi_person的【非聚集索引】
create clustered index date_person on person(date,id)
------在person表的date,age字段上面创建名为riqi_person的【复合聚集索引】
create nonclustered index date_person on person(date,age)
------在person表的date,age字段上面创建名为riqi_person的【复合非聚集索引】
sp_helpindex person
------查看person表中的聚集索引和非聚集索引
【界面操作】某个数据库>>某张表>>索引
----删除索引
drop index person.p_age
------删除person表中的名为p_age的索引
未完待续