|
first:
I'm calling the procedure from a c# code using SqlCommand object
Second :
the tabel design is the same of the design of the parameters in the procedure
Third:
i didn't put any default values for the StartDate and EndDate when Designing the tabel
the question now is :
does the SET Command modify in the tabel as it modifies in the parameter value?
|
|
|
|
|
No, the set command will only modify the variables. The data in the table will not be modified.
<br />
INSERT INTO LicenseInfo (LicenseOwner) VALUES (@LicenseOwner)<br />
<br />
SET @LicenseID = SCOPE_IDENTITY()<br />
SET @StartDate = GETDATE()<br />
SET @EndDate = GETDATE()<br />
In the above code, the only value that will get set in the new row in the table is the LicenseOwner. The other values in the table will get the default values (or NULL if no default is set).
To update the table values, you need to pass them into the table. Now, I'm assuming that LicenseID is an identity field, so that will be automatically set. This is how I would implement the procedure:
<br />
declare @MyDate datetime<br />
SET @MyDate = GETDATE() -- this will allow us to have one unique date instead of calling getdate() twice <br />
SET @StartDate = @MyDate<br />
SET @EndDate = @MyDate<br />
<br />
INSERT INTO LicenseInfo (LicenseOwner, StartDate, EndDate) <br />
VALUES (@LicenseOwner, @StartDate, @EndDate)<br />
<br />
SET @LicenseID = @@identity<br />
Hope this helps.
|
|
|
|
|
Thanks ,
I see thar this is the optimal solution for the problem
|
|
|
|
|
I am experimenting with MSDE and I've found that one long running query on one table causes other (unrelated, different tables, different machines querying) queries to hang waiting for the first query to finish. Is this a "feature" of msde or is there some settings that control how time slices are divvied up for more balance?
(Note: there is *nothing* in common between the two queries except the MSDE itself, they are different databases queried from different machines)
|
|
|
|
|
It is not clear from you post if the queries execute against different databases. If they don't you may like to consider the following (if, indeed you haven't already).
Running two consecutive queries will cause some slowdown, due to the server having to perform additional work. I would make sure that your long running query is not obtaining any locks that may prevent the other query from running. If your queries perform any joins you may find that the joins cause locks.
I also remember reading somewhere that SQL Server/MSDE will escalate locks. Perhaps you are getting page locks that are causing the second query to block, as it has data on the same page.
Have you tried moving the database(s) to a SQL Server (not MSDE) to see if you still get the same problem?
With regards to the performance of MSDE, it will slow down if you have more than '5 concurrent batch workloads'. have a look at the performance section in this page for further information.
http://www.microsoft.com/sql/techinfo/development/2000/MSDE2000.asp
I hope this helps.
Regards
Mark Smithson
|
|
|
|
|
Yup, different databases entirely. That's what I found wierd. It's a simple thing, two queries on two different databases from two different computers.
I'll have a look at that info, thanks.
"Things are more like they are now than they ever were before."
-- Dwight Eisenhower
|
|
|
|
|
What do your queries look like? If you are using "Select * Into #TempTable" then I seem to remember that the system catelog tables in the Master database get locked for the duration of the query (unfortunately all of my tuning books are at work).
Also, what isolation level are you running the queries at (Commited Read, Repeatable Read, etc.)?
Regards
Andy
|
|
|
|
|
Hello, thanks for the tips, but discovered it was an index problem (as in missing a critical index).
MSDE / SQL server sure is dependant on those indexes. The equivalent problem with the exact same sized table and same query in Access would still not have degraded that far. Of course SQL server is much faster than Access once the index is there, but it's interesting how dependant it is on them for performance and how badly performance degrades if a critical one is missing.
"Things are more like they are now than they ever were before."
-- Dwight Eisenhower
|
|
|
|
|
Greetings,
I have never used triggers in SQL, and I think they could help me with a project I am working on.
So here is my question:
1.)I have 2 testing tables setup with the folowing information to just get an understanding...
(ie) MyTableA, MyTableB
MyTableA Fields
---------------
Id (Auto-number primary key).
ItemTrackNumA (used for tracking the item in table2)
TestValue (used for storing a value).
MyTableB Fields
===============
Id (Auto-number primary key)
ItemTrackNumB (used for tracking items)
LastValue (used for storing last value used)
2.) No every time I insert a value into MyTableA I want it to either add a new record in MyTableB (if
ItemTrackB is not found in the table MyTableB),or adjust the LastValue in MyTableB if ItemTrackB is
the same as ItemTrackA.
(ie) INSERT INTO MyTableA(ItemTrackNumA, TestValue)
VALUES (3, 100)
Would then perform a lookup in MyTableB and if the ItemTrackB was equal(or found) to ItemTrackA
it would just replace LastValue in MyTableB with the TestValue from MyTableA.
In this case LastValue would not have the 100 in it.
And if the ItemTrackB wasn't found than a new record would just be inserted.
I am thinking triggers would work great for this but I have so little experiance with SQL triggers that
any suggestions would be appreciated.
Thanks in advance!!
|
|
|
|
|
It sounds like you are hoping to inhibit the insert in TableA depending upon whether some data exists in TableB. I don't believe this can be done with triggers. Typically you can define the trigger to be pre and/or post insert, but even in the pre-insert situation I don't think you can stop the insert from occurring.
Chris Meech
"what makes CP different is the people and sense of community, things people will only discover if they join up and join in." Christian Graus Nov 14, 2002.
"Microsoft hasn't ever enforced its patents. Apparently they keep them for defensive reasons only. Or, they could be waiting 'til they have a critical mass of patents, enforce them all at once and win the game of Risk that they're playing with the world." Chris Sells Feb 18, 2003.
|
|
|
|
|
Hello Chris,
That is a good point about the triggers, but in SQL server 2000 (7.0, ect) there is an available
call "INSTEAD OF", which seems to allow the ability to not have to do the insert but the problem I am
having now is accessing the params.
(ie) A simple section of code that I am checking the value to see if it is already in the table.
CREATE TRIGGER MyTrigger ON MyTableA
INSTEAD OF INSERT
AS
IF (SELECT COUNT(*)FROM MyTableA
WHERE MyTableA.Number1 = inserted.Number1) = 0
BEGIN
[...Do something...]
END
ELSE
[...Insert the new item into the database using INSERT INTO]
But the problem is "inserted.Number1" keeps saying it is undefined, and I am not sure how to get access
to the stuff that is to be inserted. I pulled the "inserted" from SQL Books online help, and I tried to
follow what they are doing, but no luck.
|
|
|
|
|
Not sure if this will help but in Oracle, you have pre-defined two variables called 'new' and 'old'. The use of them is like so
create or replace trigger transaction_create_date
before insert on transaction_table
for each row
begin
:new.create_date := sysdate;
:new.modification_date := :new.create_date;
...
Chris Meech
"what makes CP different is the people and sense of community, things people will only discover if they join up and join in." Christian Graus Nov 14, 2002.
"Microsoft hasn't ever enforced its patents. Apparently they keep them for defensive reasons only. Or, they could be waiting 'til they have a critical mass of patents, enforce them all at once and win the game of Risk that they're playing with the world." Chris Sells Feb 18, 2003.
|
|
|
|
|
That is a cool feature of oracle! Thanks for the tip!
I did finally get it working by doing the following.
I can now check to see if any of the records have that number before it is inserted.
(ie)
CREATE TRIGGER My1stTrigger ON MyTableA
INSTEAD OF INSERT
AS
IF (SELECT COUNT(*) FROM MyTableA WHERE MyTableA.Number1 = (SELECT Number1 FROM inserted)) = 0
BEGIN
INSERT INTO MyTableA SELECT Id, Number1 FROM inserted
END
ELSE
[... Do something ...]
|
|
|
|
|
Dear friends,
I want to execute a query in SQL - Server but i want the result in variable. For this purpose i am successfully doing something like this:
DECLARE @num int<br />
SELECT @num = (select salary from mytable where id=2)<br />
PRINT @num
In above query i only select one field from the table i.e salary. Now can anyone tell me that how can i collect values of multiple fields in variables. e.g
(select name, salary from mytable where id=2)
In this case i am selecting two fields from a table i.e name, salary. Now how can i get these two values in variables. Any suggestion is welcomed.
Thanks
|
|
|
|
|
Try:
DECLARE @num int, @name nvarchar(50) -- Or whatever size you need
SELECT
@name = name,
@num = salary
FROM
mytable
WHERE
id = 2
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Hello All,
Is there a way by SQL statement, if any, to rename a table in a database?
Or there any vendor specific way of doing it?
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Try a
CREATE TABLE NEWTABLE AS (SELECT * FROM OLDTABLE)
DROP TABLE OLDTABLE
there is no simple way of renaming a table
salut,
dirk
|
|
|
|
|
Thanks so much for the tip.
DiWa wrote:
there is no simple way of renaming a table
Anything simplier than what you have shown me?
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Hello Dirk,
Back again. I have just tried the statement using OLE DB (.NET) for MS Access. It is giving an error that the CREATE statment has an error. I separated the CREATE and the DROP. Is there anything missing?
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Yes, the SQL-compatibility in ACCESS is missing. The 'CREATE TABLE AS ...' statement is not supported by the JET-Engine. Sorry, you asked for a SQL-Statement, don't know how to do real SQL in Access - hate the approach MS has to standards like SQL
The statements will work on Oracle and DB2 for sure
For Access there I don't know a way to rename a table programmatically.
best regards,
dirk
|
|
|
|
|
Thanks for the explanation. I just picked a similar statement from sql.org to copy just the table structure but it also failed.
CREATE TABLE test2 () INHERITS (test)
May be I will have to disable this option for Access.
Thanks so much for the support.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Paul Selormey wrote:
any vendor specific way
For SQL Server, you can use the sp_rename stored proc.
-- Rename the customers table to custs.
EXEC sp_rename 'customers', 'custs'
Without nipples, breasts would be pointless.
|
|
|
|
|
Wow, that is cool. Thanks.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Dear CPians,
I am developing an ASP.NET app which has a lot of database work. The app has to support both SQL Server and Access and one of the requirements is be able to switch from SQL Server to Access by setting a parameter in a XML file(the XML file is read when the app starts).
I need to use the SQLClient classes. Will I be able to use the Access DB as well through the SQLClient classes?
If yes are there any drawbacks?
If no, how can I make my app capable of accessing both DBs?
What if in the future I need to support Oracle or/and DB2 as well?
Any help anyone?
Thank you!
|---------------|
| theJazzyBrain |
|---------------|
|
|
|
|
|
The best way to handle this kind of issue in the ADO.NET is to work with the interfaces, not the classes directly.
Provide a common point to create your connection object and return, IDbConnection interface. You can you this to access the data in a provider-independent way.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|