use master; #显示数据库
select top 3 * from spt_values; #显示去前3行
select * from test where id2 like '%1010%'; #查询test表中的id2字段 中带有1010的列
==================================================================
create table test(
id1 varchar(10),
id2 varchar(10),
name varchar(20)
);
insert into test values('100','1001','ccc');
insert into test values('100','1002','bbb');
insert into test values('100','1003','aaa');
insert into test values('101','1010','fff');
insert into test values('101','1011','ddd');
insert into test values('101','1012','eee');
查询语句:
select * from dbo.test order by id1 ,CHARINDEX(id2,'1011,1012,1010,1003,1002,1001,');
==================================================================
--举个例子,表名为zwj,字段为sp,查询sp字段中含有'所有'的语句为
select * from zwj where sp like '%所有%'
--表名为zwj,字段为sp,查询sp字段中含有'所'或'有'的语句为
select * from zwj where sp like '%所%' or sp like '%有%'
==================================================================
更新数据
UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值
UPDATE TABLE_NAME
SET column_name1 = VALUE WHRER column_name2 = VALUE;
==================================================================
删除字段
DELETE FROM 表名称 WHERE 列名称 = 值;
DELETE FROM Person WHERE LastName = 'Wilson' 删除person 表中的 名称lastname='wilson'的一行数据;
delete from test where id1='200';
==================================================================
T_Affairs
T_BaseLayout
T_BaseData 基础数据
StockOutForm 出库
stock 出库
T_StockDetail 单据号的详细信息
DELETE FROM [dbo].[T_StockDetail] WHERE [ID] >= 378 and [ID] <=173509;
T_StockRelation
T_BillItems 表单数据
T_Caddie 会员列表
T_BillItems
******************************************************************************************
T_Bills
T_CaddieQuit
T_Cart
TCheckin
SELECT * from T_Stock WHERE CreateDate <= '2018-01-01'
delete from [dbo].[T_Stock] WHERE [BillNo] = 'SIN171203-009'
DELETE FROM [dbo].[T_Stock] WHERE [BillNo] >= 'SIN171203-005' and [BillNo] <='SIN171204-001';
==================================================================
查询隐藏数据
select * from t_stock where createDate <= '2018-01-01' #查询小于18年之前的数据
[sql] view plain copy
EXEC sp_attach_db @dbname = '数据库名称', @filename1 = 'MDF路径',@filename2= 'LOG路径.LDF'
分离数据库命令:
[sql] view plain copy
EXEC sp_detach_db @dbname = '数据库名称'
注:要在master下执行。
显示可用的数据库
[sql] view plain copy
exec sp_helpdb
EXEC sp_attach_db @dbname = 'GameDB', @filename1 = 'C:JSQL2008MSSQL10_50.JSQL2008MSSQLDATAGameDB.MDF',@filename2= 'C:JSQL2008MSSQL10_50.JSQL2008MSSQLDATAGameDB_log.LDF'