由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - MS T-SQL 问题
相关主题
问一个SQL Server的问题求教个MS SQL的问题
[转载] Can anyone interpret this simple SQL?Problem when using SQL " Insert...." to AutoNumber.
Merge table with one single query?[转载] JDBC 处理日期的问题(日期插入数据库)
SQL Conditional SelectHow to insert CURRENT TIMESTAMP into sql
请教大牛一道有趣的SQL题How to insert a string into table? Thanks
error of executing SQL query of string concatenation (转载SQL Server stupid questions
urgent help! insert value into table[转载] 真的没有人懂 ORACLE pro*c阿? :((((
Help on Sql server huge table performanceSQL help.
相关话题的讨论汇总
话题: t1话题: table话题: timestamp话题: select话题: insert
进入Database版参与讨论
1 (共1页)
b*f
发帖数: 3154
1
这么一个例子:
IF OBJECT_ID('T1') IS NOT NULL
DROP TABLE T1;
GO
CREATE TABLE T1 (id int PRIMARY KEY, timestamp);
GO
INSERT INTO T1(id) VALUES (1);
GO
declare @v timestamp;
INSERT INTO T1(id) OUTPUT inserted.timestamp as v VALUES (10);
select @v
假设这个@v是俺想作为stored-procedure的OUT参数返回,怎样才能把inserted.
timestamp值传递给@v呢?
多谢,给俺解决问题的奉上双黄包一个...
g***l
发帖数: 18555
2
传INSERTED的值是要用TRIGGER的吧,不知道你传个这个是干什么用的
i****a
发帖数: 36252
3
DECLARE @v TABLE(result VARBINARY(8)) --note: OUTPUT is table
INSERT INTO T1(id)
OUTPUT inserted.[timestamp]
INTO @v
VALUES (2)
SELECT result
FROM @v

【在 b*f 的大作中提到】
: 这么一个例子:
: IF OBJECT_ID('T1') IS NOT NULL
: DROP TABLE T1;
: GO
: CREATE TABLE T1 (id int PRIMARY KEY, timestamp);
: GO
: INSERT INTO T1(id) VALUES (1);
: GO
: declare @v timestamp;
: INSERT INTO T1(id) OUTPUT inserted.timestamp as v VALUES (10);

i****a
发帖数: 36252
4
and if you are only processing 1 single ID at a time, just
DECLARE @v VARBINARY(8)
SELECT @v = timestamp
FROM T1
WHERE id = 10

【在 b*f 的大作中提到】
: 这么一个例子:
: IF OBJECT_ID('T1') IS NOT NULL
: DROP TABLE T1;
: GO
: CREATE TABLE T1 (id int PRIMARY KEY, timestamp);
: GO
: INSERT INTO T1(id) VALUES (1);
: GO
: declare @v timestamp;
: INSERT INTO T1(id) OUTPUT inserted.timestamp as v VALUES (10);

b*f
发帖数: 3154
5
I am trying to avoid an extra select statement for performance concern. Any
other ways?
Thanks.

【在 i****a 的大作中提到】
: and if you are only processing 1 single ID at a time, just
: DECLARE @v VARBINARY(8)
: SELECT @v = timestamp
: FROM T1
: WHERE id = 10

i****a
发帖数: 36252
6
then see my 1st post
select the single line result into your SP's output variable.

Any

【在 b*f 的大作中提到】
: I am trying to avoid an extra select statement for performance concern. Any
: other ways?
: Thanks.

b*f
发帖数: 3154
7
Is a temp table more overhead...?

【在 i****a 的大作中提到】
: then see my 1st post
: select the single line result into your SP's output variable.
:
: Any

i****a
发帖数: 36252
8
if you have a single line insert, then it's just a 1 record table
variable. table variable has a lighter overhead than a temp table.
as for method 1 vs method 2 I posted, I think method 1 is more efficient
as it doesn't require a select from T1. if you T1 has large number of rows
and not indexed.
check the query execution plan against your server. you'll probably have
to do some load testing to find out which one works better for your real
application.

【在 b*f 的大作中提到】
: Is a temp table more overhead...?
a9
发帖数: 21638
9
看了下面的讨论,为什么不想个变通的法子?还有想想你取出来干啥用?
难道你要用timestamp做索引吗?

【在 b*f 的大作中提到】
: 这么一个例子:
: IF OBJECT_ID('T1') IS NOT NULL
: DROP TABLE T1;
: GO
: CREATE TABLE T1 (id int PRIMARY KEY, timestamp);
: GO
: INSERT INTO T1(id) VALUES (1);
: GO
: declare @v timestamp;
: INSERT INTO T1(id) OUTPUT inserted.timestamp as v VALUES (10);

1 (共1页)
进入Database版参与讨论
相关主题
SQL help.请教大牛一道有趣的SQL题
Urgent help!!!error of executing SQL query of string concatenation (转载
今典问题: 这个Self Query咋写?urgent help! insert value into table
Access门外汉问题求教Help on Sql server huge table performance
问一个SQL Server的问题求教个MS SQL的问题
[转载] Can anyone interpret this simple SQL?Problem when using SQL " Insert...." to AutoNumber.
Merge table with one single query?[转载] JDBC 处理日期的问题(日期插入数据库)
SQL Conditional SelectHow to insert CURRENT TIMESTAMP into sql
相关话题的讨论汇总
话题: t1话题: table话题: timestamp话题: select话题: insert