Showing posts with label tables. Show all posts
Showing posts with label tables. Show all posts

Tuesday, March 27, 2012

@@Identity in Stored procedure

Hi,

I have a stored procedure that insert data into 2 temp tables. The problem that I have is when I insert a data into a first table, how do I get the @.@.identity value from that table and insert it into the second table?? The following code is what I have:

Create #Temp1
@.StateID Identity,
@.State nvarchar(2),
@.wage money

INSERT INTO #Temp1 (State, wage)

SELECT State, Wage FROM Table1 INNER JOIN Table2 ON Table1.Table1_ID = Table2.Table2_ID

Create #Temp2
@.ID Identity
@.EmployeeID int
@.StateID Int
@.Field1 Money
@.Field2 Money

INSERT INTO #Temp2 (EmployeeID, StateID, Field1, Field2)

SELECT EmployeeID, StateID, Field1, Field2 FROM SomeTable

So, The first part I created a #Temp1 table and insert data into the table. Then after the insert, I want the @.@.Identity value and insert into the #Temp2 table. This is my first time doing stored procedure, so, I am wondering how do I retrieve the @.@.identity value and put into the second select statement. Please help.


ahTan

DECLARE @.NewID INT

SET @.NewID = @.@.IDENTITY

OR

DECLARE @.NewID INT

SELECT @.NewID = @.@.IDENTITY

|||

instead of @.@.IDENTITY use SCOPE_IDENTITY() like

declare @._ID int

Select @._ID = SCOPE_IDENTITY()

to know why to use it, please search for SCOPE_IDENTITY in SQL SERVER books online.

thanks,

satish.

|||

SCOPE_IDENTITY() is not necessary here since the table is being created in the same stored proc. There are no triggers that would be run or no side effects to doing an insert into the table, therefore @.@.IDENTITY will work fine.

SCOPE_IDENTITY() is useful when you may have a trigger that inserts into table2 when you insert into table1, in that case getting the value used in the IDENTITY column should be retrieved with SCOPE_IDENTITY() since @.@.IDENTITY will get you value from table2 and not table1. However you don't have to worry about that here.

Regards,

Tim

|||

Thank you guys for the answer. Now, the next problem is, how do I insert the @.@.Identity value into the #TempPayroll table?

|||

ahTan:

how do I insert the @.@.Identity value into the #TempPayroll table

just save the @.@.scope_identity from the first insert into another variable and use it as input to the 2nd insert

insert into table1....
select @.Identity1 = @.@.SCOPE_IDENTITY
insert into table2 (...) values(..., @.Identity1,...)

|||

Thank you all of you for the responses. I have managed to get the stored procedure to work when I tested it using the SQL analyzer. I am getting close to what I want. Ok, the stored procedure will be called using a sqldatasource. The following code call the stored procedure:

1For Each rowAs GridViewRowIn GridView1.Rows2 SqlDataSource2.InsertCommand ="_payroll"3 SqlDataSource2.InsertCommandType = SqlDataSourceCommandType.StoredProcedure4 SqlDataSource2.InsertParameters.Add("pniID", 410)5 SqlDataSource2.Insert()6 SqlDataSource2.InsertParameters.Clear()7Next8 GridView1.Visible =False9 SqlDataSource2.SelectCommand ="_payroll"10 SqlDataSource2.SelectCommandType = SqlDataSourceCommandType.StoredProcedure11''SqlDataSource2.SelectParameters.Add("pniID", CInt(row.Cells(0).Text.Trim))12 GridView2.DataSourceID ="SqlDataSource2"13 GridView2.DataBind()
After the for each loop, I want to display all the data in a gridview.  The following code is the sql code in the stored procedure:
 
1CREATE PROCEDURE [dbo].[_payroll]2(3@.pniIDint4)56AS78SET NOCOUNT ON910CREATE TABLE #TempStates11(12StateIDInt IDENTITY,13Statenvarchar(2),14Wagemoney15)1617Create Table #TempPayrolls18(19TempPayrollIDint IDENTITY,20PNI_IDint,21EmployeeIDint,22StateIDint,23Deptnvarchar(50),24PerDiemmoney,25Mileagemoney,26Phonemoney,27Computermoney,28Cameramoney29)3031INSERT INTO #TempStates (State, Wage)32SELECT PaySheets.StateOfProject,33 PNI_Payroll.Amount * PNI_Payroll.QuantityAS Amount34FROM PNI_Payroll35INNERJOIN PNION PNI_Payroll.PNI_ID = PNI.PNI_ID36INNERJOIN TimeSheetsON PNI.TimeSheetID = TimeSheets.TimeSheetID37INNERJOIN PaySheetsON TimeSheets.PaysheetID = PaySheets.PaysheetID38WHERE (PNI.PNI_ID = @.pniID)AND (PNI_Payroll.DescriptionLIKE'%Salary%')3940DECLARE @.NewStateIDint41SELECT @.NewStateID =@.@.IDENTITY4243--SELECT * FROM #TempStates4445INSERT INTO #TempPayrolls (PNI_ID, EmployeeID, StateID)46SELECT PNI.PNI_ID, InspectorID, StateID = @.NewStateID47FROM PNI48WHERE PNI.PNI_ID = @.pniID4950INSERT INTO #TempPayrolls (PNI_ID, EmployeeID, Dept, PerDiem, Mileage, Phone, Computer, Camera)51SELECT DISTINCT PNI.PNI_ID,52 PNI.InspectorID,53 StateOfProject +' Inspector'AS Dept,54 (SELECT (Quantity * Amount)As PerDiemAmtFROM PNI_PayrollWHERE PNI_ID = @.pniIDANDDescription ='Per Diem (YES OR NO)')AS PerDiem,55 (SELECT (Quantity * Amount)As MileageAmtFROM PNI_PayrollWHERE PNI_ID = @.pniIDANDDescription ='Mileage')AS Mileage,56 (SELECT (Quantity * Amount)As PhoneAmtFROM PNI_PayrollWHERE PNI_ID = @.pniIDANDDescription ='Cell Phone (YES OR NO)')AS Phone,57 (SELECT (Quantity * Amount)As ComputerAmtFROM PNI_PayrollWHERE PNI_ID = @.pniIDANDDescription ='Computer')AS Computer,58 (SELECT (Quantity * Amount)As DigitalCamAmtFROM PNI_PayrollWHERE PNI_ID = @.pniIDANDDescription ='Camera')AS Camera59FROM PNI_PayRoll60INNERJOIN PNION PNI_PayRoll.PNI_ID = PNI.PNI_ID61INNERJOIN TimeSheetsON PNI.TimeSheetID = TimeSheets.TimeSheetID62INNERJOIN PaySheetsON TimeSheets.PaysheetID = PaySheets.PaysheetID63WHERE PNI.PNI_ID = @.pniID6465--Display data from the temp tables66SELECT TempPayrollID, PNI_ID, EmployeeID,67(SELECT StateFROM #TempStatesWHERE #TempStates.StateID = #TempPayrolls.StateID)AS State,68(SELECT WageFROM #TempStatesWHERE #TempStates.StateID = #TempPayrolls.StateID)AS Wage,69PerDiem, Mileage, Phone, Computer, Camera70FROM #TempPayrolls717273-- Turn NOCOUNT back OFF7475SET NOCOUNT OFF76GO77
So, I am wondering how am I going to display all the data in the temp tables in the gridview2. Please help
|||

Satish is correct, use SCOPE_IDENTITY(). Although fevir's explaination is correct on why @.@.IDENTITY might work, it's misusing the command, and the wrong command to use.

Just because there are no triggers TODAY, doesn't mean that there won't ever be.

|||

Motley, what about the whole YAGNI thought? Today, as it sit, the temp table it being created directly above and so no triggers exits. If you eventually did put a trigger on a temp table (not sure why you'd do this) but you'd adjust at that time.

Ultimately you're correct in that either can be used, but I'm curious about your thoughts in regard the YAGNI argument.

Regards,

Tim

|||

YAGNI would only apply if there was an easy way and more difficult approach. Since we are talking about using:

SELECT @.NewStateID =@.@.IDENTITY

or

SELECT @.NewStateID =SCOPE_IDENTITY()

I see no point in using a function that really should be reserved for someone who is very well versed in T-SQL. It's rare that @.@.IDENTITY is the correct function to use when you need an identity value. Again, in this case, we want the identity value that was just inserted by the insert just above us. The function for that is SCOPE_IDENTITY. If we wanted to know the last identity value that the system generated in the scope of our connection, that would be @.@.IDENTITY. I have yet to EVER need @.@.IDENTITY in any project I've ever done. And while using @.@.IDENTITY can cause maintenaince problems, and unexpected results, the same is not true of SCOPE_IDENTITY. It will always return the result that we are expecting whether we have a trigger on the table today, tomorrow, or never.

I say this, because I can't count the number of times that people have gotten bitten because they had to add auditting tables to track changes to a table (or replication), only to find that the application is now creating bogus data because someone decided to use @.@.IDENTITY when they should have used SCOPE_IDENTITY().

Sunday, March 25, 2012

@@ERROR & CREATE TABLE

Hi

I've been looking at scripting some create tables, but want to know if the table created successfully. I've been doing the following:

DECLARE @.ERRCODE INT

CREATE TABLE x
SET @.ERRCODE = @.@.ERROR

This works ok, if there is no erroor. However if I run this again, then obviously I get the error "This object already exists" and the script stops executing.

Is there a way that I can capture the error using @.@.ERROR and still let the script run ?

Thanks in advance

MicksterWell, you shouldn't. "On Error Resume Next" is not present in T-SQL. What you should do is perform a validation for presence of object before attempting to create it.if objectproperty(object_id('dbo.x'), 'isusertable')=1 drop table dbo.x

create table dbo.x (f1 int, ...)|||Thanks, but I already understand that I should check for the existance of the object - as stated in my last mail. I want to check the table is being created correctly incase of other events, like permissions, file full, etc.

@@DBTS

Hi

There are tables in our database with timestamp column. As and when rows are updated/inserted in these tables, the timestamp column is getting populated which is getting reflected in the @.@.DBTS system variable.

However when we take the FULL database backup and restore the database, the @.@.BSTS is not showing the same timestamp value as it was when full DB backup was done (the behavior is unpredictable - once i did manage to get the correct @.@.DBTS value).

Does backup and restore process have any effects on the @.@.DBTS system variable.

Any guidance on parameter settings for Backup and restore will be appreciated to resolve this issue.

Cheers

Nishant Hate


I am assuming that is because Timestamp is a binary datatype used for row versioning, if you want the timeback you need to use datetime datatype. If you go to the Timestamp section of the link below Microsoft explains it in detail. Hope this helps.

http://msdn2.microsoft.com/en-us/library/ms191240.aspx

|||

Hi

Thanks for your prompt response.

Let me give you background on the issue

There is a source system which is already developed from which i have to take incremental data every day and load into my warehouse.

There are no datetime fields in the source system for me to use and there is no scope for us to get the source system modified,

however each table is having the timestamp column which should give me daily new/updated records in the source system.

We can acheive this by storing the last loaded Timestamp in a control table and getting the latest timestamp using @.@.DBTS

Using this range we can get the incremental data from the source system.

This works fine.

However assuming that there is some issue with the source system and the database has to be restored from the backup.

Ideally i would have liked the @.@.DBTS to have the same value that was there when the backup was taken.

But the @.@.DBTS value is not coming the same infact it moves forward.

Logically @.@.DBTS moving forward should also be fine as I am interested in the records within the range and all the records will be included in the range.

So the question now is should I rely on @.@.DBTS even though it is different from the one which was there at the time of backup.

or am i better off to aviod this because of its unpredictable nature and build something to simulate the @.@.DBTS functionality i.e. Take max(timestamp) across all tables.

Please do let me know your views.

Cheers

Nishant hate

Moving table with data to another database in sql Express 2005?

How to move some tables with data & procedures etc from 1 database to another in sql server 2005 express edition.

i did by scripting but i transfer tables and procedures and not data

data is the problem.

tnx

I'm already discussing this with you here

http://forums.asp.net/thread/1299924.aspx

sql

Monday, March 19, 2012

.TPS tables via SQL Server 2000

Hi,
Is there any way to open .TPS(TopSpeed) tables via SQL Server 2000?Originally posted by JoTech
Hi,

Is there any way to open .TPS(TopSpeed) tables via SQL Server 2000?

not much sure about this but there are odbc drivers available for importing .tps tables.
check :
http://www.softvelocity.com/products/pr_database_tsodbc.htm

Thursday, March 8, 2012

.NET Performance - Native vs OLE DB

Using a local instance of SQL Server 2000 and .NET I have managed to insert 4000 rows across multiple tables using the OLE DB provider in 11 seconds but when using the native provider it takes 13 seconds.
I was under the impression the native provider should enhance performance not decrease it? Why is this?
Thanks, Robby
By native provider, do you mean System.Data.SqlClient? In general SqlClient
is a good deal faster than using the combination of System.Data.OleDb and
the native oledb provider for sql server. To comment further, I'd need to
know more about your scenario.
Thanks,
Dave
"Robby White" <Robby White@.discussions.microsoft.com> wrote in message
news:04E120F8-5A6E-42F9-80E9-8BBD32B887C3@.microsoft.com...
> Using a local instance of SQL Server 2000 and .NET I have managed to
insert 4000 rows across multiple tables using the OLE DB provider in 11
seconds but when using the native provider it takes 13 seconds.
> I was under the impression the native provider should enhance performance
not decrease it? Why is this?
> Thanks, Robby
|||Yes I mean the System.Data.SqlClient provider.
Inserting 4000 records into SQL Server 2000
using the System.Data.SqlClient took 14 seconds
using the System.Data.Odbc took 13 seconds
using the System.Data.OleDb took 12 seconds
I have tried running these tests in different orders also and get the same results. I realise the times are close but I am concerned about scalibility.
Robby White
"David Schleifer [MSFT]" wrote:

> By native provider, do you mean System.Data.SqlClient? In general SqlClient
> is a good deal faster than using the combination of System.Data.OleDb and
> the native oledb provider for sql server. To comment further, I'd need to
> know more about your scenario.
> Thanks,
> Dave
> "Robby White" <Robby White@.discussions.microsoft.com> wrote in message
> news:04E120F8-5A6E-42F9-80E9-8BBD32B887C3@.microsoft.com...
> insert 4000 rows across multiple tables using the OLE DB provider in 11
> seconds but when using the native provider it takes 13 seconds.
> not decrease it? Why is this?
>
>
|||The insert operation is a fairly simple one, compared to other provider
operations such as reading data, so it's hard for any one provider to exceed
another once it's been reasonbly optimized. If you want to compare overall
provider performance, whatever benchmark you choose would have to include a
fair measure of read operations, which is one of the areas where SqlClient
really outperforms the oledb managed provider.
That said, when I tried a simple test with 16000 distinct insert operations
(i.e. seperate round trip for each), I got results for SqlClient that were
1-2% better than the OleDb provider. I think it's fair to say that the two
providers are basically equivalent for many types of insert operations, but
overall for best performance you will be better off with SqlClient.
If you are only interested in insert performance, you will probably want to
check out the Whidbey release of .NET, where SqlClient supports a bulk load
api.
"Robby White" <RobbyWhite@.discussions.microsoft.com> wrote in message
news:8A9CA873-B3B5-44B7-B2D9-296FFE988FC5@.microsoft.com...
> Yes I mean the System.Data.SqlClient provider.
> Inserting 4000 records into SQL Server 2000
> using the System.Data.SqlClient took 14 seconds
> using the System.Data.Odbc took 13 seconds
> using the System.Data.OleDb took 12 seconds
> I have tried running these tests in different orders also and get the same
results. I realise the times are close but I am concerned about
scalibility.[vbcol=seagreen]
> Robby White
> "David Schleifer [MSFT]" wrote:
SqlClient[vbcol=seagreen]
and[vbcol=seagreen]
to[vbcol=seagreen]
performance[vbcol=seagreen]
|||Thanks for your help...
"David Schleifer [MSFT]" wrote:

> The insert operation is a fairly simple one, compared to other provider
> operations such as reading data, so it's hard for any one provider to exceed
> another once it's been reasonbly optimized. If you want to compare overall
> provider performance, whatever benchmark you choose would have to include a
> fair measure of read operations, which is one of the areas where SqlClient
> really outperforms the oledb managed provider.
> That said, when I tried a simple test with 16000 distinct insert operations
> (i.e. seperate round trip for each), I got results for SqlClient that were
> 1-2% better than the OleDb provider. I think it's fair to say that the two
> providers are basically equivalent for many types of insert operations, but
> overall for best performance you will be better off with SqlClient.
> If you are only interested in insert performance, you will probably want to
> check out the Whidbey release of .NET, where SqlClient supports a bulk load
> api.
>
> "Robby White" <RobbyWhite@.discussions.microsoft.com> wrote in message
> news:8A9CA873-B3B5-44B7-B2D9-296FFE988FC5@.microsoft.com...
> results. I realise the times are close but I am concerned about
> scalibility.
> SqlClient
> and
> to
> performance
>
>

.NET Performance - Native vs OLE DB

Using a local instance of SQL Server 2000 and .NET I have managed to insert
4000 rows across multiple tables using the OLE DB provider in 11 seconds but
when using the native provider it takes 13 seconds.
I was under the impression the native provider should enhance performance no
t decrease it? Why is this?
Thanks, RobbyBy native provider, do you mean System.Data.SqlClient? In general SqlClient
is a good deal faster than using the combination of System.Data.OleDb and
the native oledb provider for sql server. To comment further, I'd need to
know more about your scenario.
Thanks,
Dave
"Robby White" <Robby White@.discussions.microsoft.com> wrote in message
news:04E120F8-5A6E-42F9-80E9-8BBD32B887C3@.microsoft.com...
> Using a local instance of SQL Server 2000 and .NET I have managed to
insert 4000 rows across multiple tables using the OLE DB provider in 11
seconds but when using the native provider it takes 13 seconds.
> I was under the impression the native provider should enhance performance
not decrease it? Why is this?
> Thanks, Robby|||Yes I mean the System.Data.SqlClient provider.
Inserting 4000 records into SQL Server 2000
using the System.Data.SqlClient took 14 seconds
using the System.Data.Odbc took 13 seconds
using the System.Data.OleDb took 12 seconds
I have tried running these tests in different orders also and get the same r
esults. I realise the times are close but I am concerned about scalibility.
Robby White
"David Schleifer [MSFT]" wrote:

> By native provider, do you mean System.Data.SqlClient? In general SqlClien
t
> is a good deal faster than using the combination of System.Data.OleDb and
> the native oledb provider for sql server. To comment further, I'd need to
> know more about your scenario.
> Thanks,
> Dave
> "Robby White" <Robby White@.discussions.microsoft.com> wrote in message
> news:04E120F8-5A6E-42F9-80E9-8BBD32B887C3@.microsoft.com...
> insert 4000 rows across multiple tables using the OLE DB provider in 11
> seconds but when using the native provider it takes 13 seconds.
> not decrease it? Why is this?
>
>|||The insert operation is a fairly simple one, compared to other provider
operations such as reading data, so it's hard for any one provider to exceed
another once it's been reasonbly optimized. If you want to compare overall
provider performance, whatever benchmark you choose would have to include a
fair measure of read operations, which is one of the areas where SqlClient
really outperforms the oledb managed provider.
That said, when I tried a simple test with 16000 distinct insert operations
(i.e. seperate round trip for each), I got results for SqlClient that were
1-2% better than the OleDb provider. I think it's fair to say that the two
providers are basically equivalent for many types of insert operations, but
overall for best performance you will be better off with SqlClient.
If you are only interested in insert performance, you will probably want to
check out the Whidbey release of .NET, where SqlClient supports a bulk load
api.
"Robby White" <RobbyWhite@.discussions.microsoft.com> wrote in message
news:8A9CA873-B3B5-44B7-B2D9-296FFE988FC5@.microsoft.com...
> Yes I mean the System.Data.SqlClient provider.
> Inserting 4000 records into SQL Server 2000
> using the System.Data.SqlClient took 14 seconds
> using the System.Data.Odbc took 13 seconds
> using the System.Data.OleDb took 12 seconds
> I have tried running these tests in different orders also and get the same
results. I realise the times are close but I am concerned about
scalibility.[vbcol=seagreen]
> Robby White
> "David Schleifer [MSFT]" wrote:
>
SqlClient[vbcol=seagreen]
and[vbcol=seagreen]
to[vbcol=seagreen]
performance[vbcol=seagreen]|||Thanks for your help...
"David Schleifer [MSFT]" wrote:

> The insert operation is a fairly simple one, compared to other provider
> operations such as reading data, so it's hard for any one provider to exce
ed
> another once it's been reasonbly optimized. If you want to compare overall
> provider performance, whatever benchmark you choose would have to include
a
> fair measure of read operations, which is one of the areas where SqlClient
> really outperforms the oledb managed provider.
> That said, when I tried a simple test with 16000 distinct insert operation
s
> (i.e. seperate round trip for each), I got results for SqlClient that were
> 1-2% better than the OleDb provider. I think it's fair to say that the two
> providers are basically equivalent for many types of insert operations, bu
t
> overall for best performance you will be better off with SqlClient.
> If you are only interested in insert performance, you will probably want t
o
> check out the Whidbey release of .NET, where SqlClient supports a bulk loa
d
> api.
>
> "Robby White" <RobbyWhite@.discussions.microsoft.com> wrote in message
> news:8A9CA873-B3B5-44B7-B2D9-296FFE988FC5@.microsoft.com...
> results. I realise the times are close but I am concerned about
> scalibility.
> SqlClient
> and
> to
> performance
>
>

Saturday, February 25, 2012

.ndf

Is there a way to attach an .ndf file from database A to database B and move whatever tables and indexes in the data file to database B?You can do it using SP_ATTACH_DB, for instance :
[/B]
EXEC sp_attach_db @.dbname = N'MyDB',
@.filename1 = N'F:\mssql7\data\My_Data.mdf',
@.filename2 = N'F:\mssql7\data\My_Data.Ndf',
@.filename3 = N'F:\mssql7\data\My_log.ldf'
[/B]
Refer to books online for more information on the SP.

Friday, February 24, 2012

.dat and .idx

I have .idx and .dat files. I need an ODBC driver to allow me to attach to
or import these tables. Anyone have any clue how to help me?idx is the default for index creation statement. I don't know recognize the
.dat extension. You should be able to run the idx file as a normal SQL
statement.
--
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Ben Watts" <ben.watts@.aaronnickellhomes.com> wrote in message
news:u46gUx6yGHA.2036@.TK2MSFTNGP05.phx.gbl...
>I have .idx and .dat files. I need an ODBC driver to allow me to attach to
>or import these tables. Anyone have any clue how to help me?
>|||Ben Watts wrote:
> I have .idx and .dat files. I need an ODBC driver to allow me to attach to
> or import these tables. Anyone have any clue how to help me?
>
What are these files from?
--
Tracy McKibben
MCDBA
http://www.realsqlguy.com

.dat and .idx

I have .idx and .dat files. I need an ODBC driver to allow me to attach to
or import these tables. Anyone have any clue how to help me?idx is the default for index creation statement. I don't know recognize the
.dat extension. You should be able to run the idx file as a normal SQL
statement.
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Ben Watts" <ben.watts@.aaronnickellhomes.com> wrote in message
news:u46gUx6yGHA.2036@.TK2MSFTNGP05.phx.gbl...
>I have .idx and .dat files. I need an ODBC driver to allow me to attach to
>or import these tables. Anyone have any clue how to help me?
>|||Ben Watts wrote:
> I have .idx and .dat files. I need an ODBC driver to allow me to attach to
> or import these tables. Anyone have any clue how to help me?
>
What are these files from?
Tracy McKibben
MCDBA
http://www.realsqlguy.com

Sunday, February 19, 2012

... not in ... what is the fastest way ?

Hi,
i have two tables, each has a columnn called "value". Now i want all
"values" from table_1 which does not exist in table_2. I tried:
select table_1.value from table_1 where not exists (select * from table_2
where table_2.value = table_1.value)
Is this the fastest way (in SQL-Server2000)?
thanks,
HelmutHi Helmut,
Yes.
Make sure there is an index on table2.value.
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"helmut woess" <hw@.iis.at> wrote in message
news:1tm1fparsdfl.w6pfxn05crxk.dlg@.40tude.net...
> Hi,
> i have two tables, each has a columnn called "value". Now i want all
> "values" from table_1 which does not exist in table_2. I tried:
> select table_1.value from table_1 where not exists (select * from table_2
> where table_2.value = table_1.value)
> Is this the fastest way (in SQL-Server2000)?
> thanks,
> Helmut|||Your query just might be the fastest, but compare in Profiler with this one:
select value
from table_1
left join table_2
on table_2.value = table_1.value
where (table_2.value is null)
ML
http://milambda.blogspot.com/|||Am Tue, 3 Jan 2006 01:34:05 -0800 schrieb ML:

> Your query just might be the fastest, but compare in Profiler with this on
e:
> select value
> from table_1
> left join table_2
> on table_2.value = table_1.value
> where (table_2.value is null)
>
> ML
> --
> http://milambda.blogspot.com/
Thanks, i checked it with the profiler and it seems to be nearly indentical
(i have not so much records now). But your query needs some rows more and
has an additional filter, so if the table has millions of records maybe my
way is faster.
bye,
helmut|||Am Tue, 3 Jan 2006 09:36:12 -0000 schrieb Tony Rogerson:

> Hi Helmut,
> Yes.
> Make sure there is an index on table2.value.
I have an index on it - thanks,
Helmut|||Please, let us know when you test it on millions of rows. We'd like to know.
:)
ML
http://milambda.blogspot.com/

*= Left Outer Join

I have three related tables A,B and C. In sql server 2000 I can run next query:
select * from
A left outer join B on A.fk=B.i
left outer join C on B.fk=C.i
but below query give me an "invalid outer combination" error:
select * from
A,B,
where
A.fk*=B.id an
B.fk*=C.i
It seems outer combinations configured in where clause are limited to two tables, although I have seen some examples of more than two tables in the web (but unfortunately author didnâ't inform about sql version). Has changed the behaviour of *= changed in the 2000 versionWhy do you want to use deprecated syntax that will not be supported in a
future version?
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"David Palomar" <anonymous@.discussions.microsoft.com> wrote in message
news:5F0EAF81-A9CD-4E0C-A57D-DC5CC8CDB47F@.microsoft.com...
> I have three related tables A,B and C. In sql server 2000 I can run next
query:
> select * from
> A left outer join B on A.fk=B.id
> left outer join C on B.fk=C.id
> but below query give me an "invalid outer combination" error:
> select * from
> A,B,C
> where
> A.fk*=B.id and
> B.fk*=C.id
> It seems outer combinations configured in where clause are limited to two
tables, although I have seen some examples of more than two tables in the
web (but unfortunately author didnâ?Tt inform about sql version). Has
changed the behaviour of *= changed in the 2000 version?
>|||Thatâ's very true Aaron, but I',m using an automatic persistence tool which generates this kind of joins and I can't do anything about. So, if possible, I would like to know why it doesn't works in sql server 2000 (in order to complain) and if there would be a way to circumvent the problem in the mean time.
-- Aaron Bertrand - MVP wrote: --
Why do you want to use deprecated syntax that will not be supported in
future version
--
Aaron Bertran
SQL Server MV
http://www.aspfaq.com
"David Palomar" <anonymous@.discussions.microsoft.com> wrote in messag
news:5F0EAF81-A9CD-4E0C-A57D-DC5CC8CDB47F@.microsoft.com..
> I have three related tables A,B and C. In sql server 2000 I can run nex
query
>> select * fro
> A left outer join B on A.fk=B.i
> left outer join C on B.fk=C.i
>> but below query give me an "invalid outer combination" error
>> select * fro
> A,B,
> wher
> A.fk*=B.id an
> B.fk*=C.i
>> It seems outer combinations configured in where clause are limited to tw
tables, although I have seen some examples of more than two tables in th
web (but unfortunately author didnâ?Tt inform about sql version). Ha
changed the behaviour of *= changed in the 2000 version
>|||There are restriction for old-style joins. I don't know them all by heart
(you should be able to find them in Books Online), but I believe that one is
that you can't do more than one OJ in a query. You really need to get a
version of your tool that supports the new proper way to specify an outer
join.
--
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"David Palomar" <anonymous@.discussions.microsoft.com> wrote in message
news:3DF4DD3C-DF25-42C6-B8C4-5B504F1E5A04@.microsoft.com...
> That's very true Aaron, but I',m using an automatic persistence tool which
generates this kind of joins and I can't do anything about. So, if
possible, I would like to know why it doesn't works in sql server 2000 (in
order to complain) and if there would be a way to circumvent the problem in
the mean time.
> -- Aaron Bertrand - MVP wrote: --
> Why do you want to use deprecated syntax that will not be supported
in a
> future version?
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.aspfaq.com/
>
>
> "David Palomar" <anonymous@.discussions.microsoft.com> wrote in
message
> news:5F0EAF81-A9CD-4E0C-A57D-DC5CC8CDB47F@.microsoft.com...
> > I have three related tables A,B and C. In sql server 2000 I can run
next
> query:
> >> select * from
> > A left outer join B on A.fk=B.id
> > left outer join C on B.fk=C.id
> >> but below query give me an "invalid outer combination" error:
> >> select * from
> > A,B,C
> > where
> > A.fk*=B.id and
> > B.fk*=C.id
> >> It seems outer combinations configured in where clause are limited
to two
> tables, although I have seen some examples of more than two tables in
the
> web (but unfortunately author didnâ?Tt inform about sql version). Has
> changed the behaviour of *= changed in the 2000 version?
> >

*= Left Outer Join

I have three related tables A,B and C. In sql server 2000 I can run next que
ry:
select * from
A left outer join B on A.fk=B.id
left outer join C on B.fk=C.id
but below query give me an "invalid outer combination" error:
select * from
A,B,C
where
A.fk*=B.id and
B.fk*=C.id
It seems outer combinations configured in where clause are limited to two ta
bles, although I have seen some examples of more than two tables in the web
(but unfortunately author didn’t inform about sql version). Has changed th
e behaviour of *= changed i
n the 2000 version?Why do you want to use deprecated syntax that will not be supported in a
future version?
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"David Palomar" <anonymous@.discussions.microsoft.com> wrote in message
news:5F0EAF81-A9CD-4E0C-A57D-DC5CC8CDB47F@.microsoft.com...
> I have three related tables A,B and C. In sql server 2000 I can run next
query:
> select * from
> A left outer join B on A.fk=B.id
> left outer join C on B.fk=C.id
> but below query give me an "invalid outer combination" error:
> select * from
> A,B,C
> where
> A.fk*=B.id and
> B.fk*=C.id
> It seems outer combinations configured in where clause are limited to two
tables, although I have seen some examples of more than two tables in the
web (but unfortunately author didn?Tt inform about sql version). Has
changed the behaviour of *= changed in the 2000 version?
>|||That’s very true Aaron, but I',m using an automatic persistence tool which
generates this kind of joins and I can't do anything about. So, if possibl
e, I would like to know why it doesn't works in sql server 2000 (in order to
complain) and if there wou
ld be a way to circumvent the problem in the mean time.
-- Aaron Bertrand - MVP wrote: --
Why do you want to use deprecated syntax that will not be supported in a
future version?
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"David Palomar" <anonymous@.discussions.microsoft.com> wrote in message
news:5F0EAF81-A9CD-4E0C-A57D-DC5CC8CDB47F@.microsoft.com...
> I have three related tables A,B and C. In sql server 2000 I can run next
query:
> A left outer join B on A.fk=B.id
> left outer join C on B.fk=C.id
> A,B,C
> where
> A.fk*=B.id and
> B.fk*=C.id
tables, although I have seen some examples of more than two tables in the
web (but unfortunately author didna?Tt inform about sql version). Has
changed the behaviour of *= changed in the 2000 version?
>|||There are restriction for old-style joins. I don't know them all by heart
(you should be able to find them in Books Online), but I believe that one is
that you can't do more than one OJ in a query. You really need to get a
version of your tool that supports the new proper way to specify an outer
join.
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=...ublic.sqlserver
"David Palomar" <anonymous@.discussions.microsoft.com> wrote in message
news:3DF4DD3C-DF25-42C6-B8C4-5B504F1E5A04@.microsoft.com...
> That's very true Aaron, but I',m using an automatic persistence tool which
generates this kind of joins and I can't do anything about. So, if
possible, I would like to know why it doesn't works in sql server 2000 (in
order to complain) and if there would be a way to circumvent the problem in
the mean time.
> -- Aaron Bertrand - MVP wrote: --
> Why do you want to use deprecated syntax that will not be supported
in a
> future version?
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.aspfaq.com/
>
>
> "David Palomar" <anonymous@.discussions.microsoft.com> wrote in
message
> news:5F0EAF81-A9CD-4E0C-A57D-DC5CC8CDB47F@.microsoft.com...
next
> query:
to two
> tables, although I have seen some examples of more than two tables in
the
> web (but unfortunately author didn?Tt inform about sql version). Has
> changed the behaviour of *= changed in the 2000 version?|||Thanks for the clue Tibor, i'll try to follow it.
-- Tibor Karaszi wrote: --
There are restriction for old-style joins. I don't know them all by heart
(you should be able to find them in Books Online), but I believe that one is
that you can't do more than one OJ in a query. You really need to get a
version of your tool that supports the new proper way to specify an outer
join.
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=...ublic.sqlserver
"David Palomar" <anonymous@.discussions.microsoft.com> wrote in message
news:3DF4DD3C-DF25-42C6-B8C4-5B504F1E5A04@.microsoft.com...
> That's very true Aaron, but I',m using an automatic persistence tool which
generates this kind of joins and I can't do anything about. So, if
possible, I would like to know why it doesn't works in sql server 2000 (in
order to complain) and if there would be a way to circumvent the problem in
the mean time.
in a
> future version?
> Aaron Bertrand
> SQL Server MVP
> http://www.aspfaq.com/
message
> news:5F0EAF81-A9CD-4E0C-A57D-DC5CC8CDB47F@.microsoft.com...
next
> query:
to two
> tables, although I have seen some examples of more than two tables in
the
> web (but unfortunately author didna?Tt inform about sql version). Ha
s
> changed the behaviour of *= changed in the 2000 version?

Thursday, February 16, 2012

**Grant alter table to some table!**

Hi
I'm working with SQL 2000 and I want to know if it's possible to grant a
user to alter some tables of a database. can I do it? how?
Any help would be thankful.Yes , add him/her to db_ddladmin database fixed role
<R> wrote in message news:ops7kmsz1gmw7tkz@.system109.parskhazar.net...
> Hi
> I'm working with SQL 2000 and I want to know if it's possible to grant a
> user to alter some tables of a database. can I do it? how?
> Any help would be thankful.

Monday, February 13, 2012

**fetch the related tables of a particular table**

Hi
I'm working with SQL server 2000, and I want to know how can I find the
list of tables which have relation to a particular table. in another word,
would it be possible to fetch the name of those tables by a simple Sql
statement?
Any help would be greatly appreciated.Hi
Look at INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS.
John
<R> wrote in message news:ops6lmu3xamw7tkz@.system109.parskhazar.net...
> Hi
> I'm working with SQL server 2000, and I want to know how can I find the
> list of tables which have relation to a particular table. in another word,
> would it be possible to fetch the name of those tables by a simple Sql
> statement?
> Any help would be greatly appreciated.