Showing posts with label record. Show all posts
Showing posts with label record. Show all posts

Friday, March 30, 2012

relationships, primary key sql2000 question.

Hello,

I have 2 tables with a field called userid which is uniqueidentifier and they are both primary keys.

When I add a record to table1 and the userid field is filled, what is the best way to update table 2 with the same record.

Is there an sql function that will update automatically or do I have to write code in vb.net to select the record form table1 and insert into table2.

Thanks

Peter

If you wanted to do it relationship, one of the keys would have to be a foreign key and the other the primary key, probably using a 1 to 1 relationship.

If you want to use two primary keys, you would either need to do it by T-SQL or on the .NET Server end, ex. with VB.NET.

|||

What you are looking for is called a DRI(declarative referential integrity) constraint. You create it with the enable relationship dialog box at the top of Management Studio and look for option Cascade on Update. The two links below one explains DRI and the second is a walkthrough to enable it. Hope this helps.

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

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

|||

Thanks guys, working through links now.

Peter

sql

Friday, March 23, 2012

Relace function of mysql

Hi,
Want to know that is their any option of inserting a record if the record does not exist in the table..while firing update query.
In mysql, we have replace which updates or inserts the record.
do let me know
thanx,
vivek.No SQL Server does not have a command like that. In my case all of my commands are done within a stored procedure, so I first check to see if the record exists, if yes then UPDATE else INSERT.

IF EXISTS (SELECT * FROM myTable WHERE pkey = @.pkey) BEGIN
UPDATE myTable
.
.
.
.
END ELSE
INSERT myTable
.
.
.
.
END|||Thanx,

will surely try with Stored procs.

regards,
vivek.

Saturday, February 25, 2012

Registering User changing data

Hello there
I have many tables that i would like to kbow on each record who inserted,
updated data and when it happend?
For this i've learned about function call SUSER_SNAME() that always gives me
the current user who is in the system. For insert case i've solved it
simply: added two fields:
ChangeBy with the SUSER_SNAME() function as default value
ChangeAt with the GETDATE() function as default value
This works fine for Inserting.
But what i need to do for updating: do i have to use a trigger for this?> But what i need to do for updating: do i have to use a trigger for this?
Yes, you can use a trigger. You can also use SQL Profiler for auditing -
check
http://www.sqlservercentral.com/col...ityLearning.com