primary key and foreign Key????

 Hi i have 2 table..

 

Table1

UID         Username

1               AB

2               CD

3               DD

 

Table 2

ITEM       Price          UID

POO1      20.00          1

POO2      10.00          2

POO3       15.00         1

 

Now i am letting the Admin to delete the user in table1

But since UID 1 and 2 are in use so i shouldn't let the admin delete them and showed a msg that they are in use so u can't delete

and if the admin try to delete the UID 3 then i should let admin delete...

How to do????


 


Abhi
0
abhishek0410
3/30/2009 2:09:18 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

5 Replies
1072 Views

Similar Articles

[PageSpeed] 2

do you want to check this using SQL or using C# coding? if in SQL you can check if this particular id is present in the second table or not or if its in C# you just write an SP with a select statement and pass the id as parameter to see if it returns any rows. if there is any rows returned then you should not delete else delete it.
Cheers
Bino
www.codepal.co.in

Please Mark as Answer if you find the post useful.
0
binobose
3/30/2009 2:47:27 PM

IF EXISTS(SELEXT 'X' from TABLE2 where UID = @UID)

    BEGIN

         SELECT * from Table2 where UID = @UID

    END

Write the above logic in the SP and pass UID as Parameter. If you get rows then Table2 has Data else UID isn't present.


Avi
0
vemulapalli26
3/30/2009 3:09:23 PM

 Hi,abhishek

Make  UID        column in Table1 as Primary Key

and 

 Make  UID  column in Table2 as Foreign Key to the UID Column In Table 1


RAGHAV

MVP ASP/ASP.Net Read My Blog


MARK THE POST AS ANSWER IF IT HELPS U.


"Success doesn't come to you…you go to it."--Marva Collins




"Success does not come to those who wait . . . and it does not wait for anyone to come to it." Anonymous


0
raghav_khunger
3/30/2009 4:52:53 PM

 

Ya i did that raghav...But i wanted to do with code and show a pop up msg that UID is in use to so don't modify or delete....

i think i need to fire a query n search weather it is in use or not...if it is in use then don't delete or modify..

 

 


Abhi
0
abhishek0410
3/31/2009 4:30:17 AM

Hi, abhishek

U can  do that with raiserror. Take help from these

http://forums.asp.net/p/1355511/2782368.aspx#2782368
http://forums.asp.net/p/1380158/2915767.aspx#2915767
 http://forums.asp.net/p/1346140/2736471.aspx
http://forums.asp.net/p/1338428/2704670.aspx
http://forums.asp.net/p/1338801/2704459.aspx

 


RAGHAV

MVP ASP/ASP.Net Read My Blog


MARK THE POST AS ANSWER IF IT HELPS U.


"Success doesn't come to you…you go to it."--Marva Collins




"Success does not come to those who wait . . . and it does not wait for anyone to come to it." Anonymous


0
raghav_khunger
3/31/2009 5:05:55 AM
Reply:

Similar Artilces:

Clustered Primary Key and Foreign Key: T-SQL
I am having a little trouble getting this to work right, but have come a ways since I started this.......other tables created first and with no problems..... then these two with the last table being the problemI need to set one foreign key in the second table referencing the first table.But, the primary key is clustered with the two foreign keys and I get the error....There are no primary or candidate keys in the referenced table 'courseScores' that match the referencing column list in the foreign key 'FK_course'.CREATE TABLE dbo.courseScores   (     course...

integer primary/foreign key vs. varchar(255) primary/foreign key
Hello. Is there any principal performance (or some other) difference between using the integer primary/foreign key and using the string (varchar(255)) keys in queries that use tables joins? Server is Sybase SQL Anywhere 5.5.04 Yes! The primary key will only be made up of 12 bytes. By using an integer you ensure that your entire column is in the key. -- Jim Egan [TeamPS] Dynamic Data Solutions, Inc. http://www.dyn-data.com Houston, TX *********************************************************** Enterprise Applications in Your F...

SQL statement failed: (-194) No primary key value for foreign key
I'm getting this error message sporadically when my remote sites are replicating to my central server. The odd thing is the record that is the primary key value does exist! I'm at a lost...Does any have any idea, why this may be happening? Thanks Tasha Did the record exist at the time the error was reported? I have seen cases before where the Parent record is physically sent to the remote *after* the Child record. This would explain why the error was legitimately reported but when you look at the database later the Parent record now exists. -- -------------...

Primary Key/Foreign Key
Can I use SQL Commands to add Primary key or reference keys to existed tables? (Not a new table, that's why I can't use CREATE TABLE command.) If does, could someone give me some sample codes? Thanks. Hi John, What you need is the ALTER TABLE statement. Look for it in SQLA help for the syntax. Regards, Nat. John Chyan wrote in message <35A4FF5D.5F192806@dissol.com>... >Can I use SQL Commands to add Primary key or reference keys to existed >tables? (Not a new table, that's why I can't use CREATE TABLE command.) > >If does, could someone ...

Primary key
Hello, I've got a modeling problem betwin a conceptual model and a physical model and espacially about the foreign key. See below the illustrated exemple of the problem : -Whether the entity � ARTICLE � with two informations : CODE & WORDING -Whether the entity � UNITE � with two informations : CODE & WORDING An article has necesseraly three unity, the unity of command, of storage and of sails. These three unity can be differents. Conceptual model phycical model The generated physical model doesn't suitable me. How ...

foreign key as a primary key
hi, I am using a foreign key (which is a primary key in a secondary table) as a primary key in a primary table. There is also another primary key in the primary table. Do You have to declare the foregin key as a primary key ? regards Jan Eikeland email:jaeikela@c2i.net url :http://home.c2i.net/jaeikela In article <368b0234.5056065@forums.powersoft.com>, jaeikela@c2i.net says... > hi, > > I am using a foreign key (which is a primary key in a secondary table) > as a primary key in a primary table. > There is also another primary key in the primary table...

Primary key/Foreign key again
Thanks, Nat and David. Under "SQL Anywhere", I get into ISQL to use "ALTER TABLE" command to add my primary key: ALTER TABLE Client ADD PRIMARY KEY (SYSID) I got an error: user 'dba' has the row in 'Client' locked. How can I release the locking condition? Click on another table in Sybase Central. Is suspect this is the issue. Dave Wolf Jaguar Product Team John Chyan wrote: > Thanks, Nat and David. > > Under "SQL Anywhere", I get into ISQL to use "ALTER TABLE" command > to add my primary key: > ...

SQL statement failed, no primary key value for foreign key ... in table ...
Problem: SQL statement failed, no primary key value for foreign key ... in table ... After deleting or changing primary key values in either consolidated or remote database. Question: Are there any triggers that can resolve inserting a record that has a foreign key value with no existing primary key value in primary table? Description: We have a serious problem with the dbremote program. I think it's a general problem that could appear in every database with related tables. Everytime the problem turns up we must create new remote databases from the consolidated datab...

Keys, keys,keys...
Just installed PGP 6.5.8 and all is running fine, so far :-) Question: When I opened the PGP Keys window for the first time, apart from the *Create Key* wizard, there are about 50 odd keys belonging to various and sundry at NAI. Were these supplied for a purpose or only for illustration? Is there any reason they could not or should no be deleted? Question 2: I sent someone an encrypted test message using that person's public key. It went off fine except, I am left with only the encrypted eMail. What setting should I change in order for my eMail client (Outlook 2000) ...

Primary Key Prob with SQL table innerjoin with primary key
Hello Exception Details: System.Data.MissingPrimaryKeyException: Table doesn't have a primary key. I have used Stored Procedure in SQL with innerjoin. I think this Stored Procedure is problem because when I use one table with primary key rather using innerjoin to get data from 2 SQL tables I don't have this Table doesn't have a primary key: CREATE proc dbo._BookLink As select Convert(nvarchar(10),BookID)as BookId, CategoryName,Title, Author, Publisher, PublicationDate, ISBN, Price, BriefDesc, FullDesc, [Image], link, htmlready from dbo.BookCategory inner join dbo.B...

No primary key value for foreign key
Hi, I tried to: alter table sa.shipitems add foreign key FK_SHIPITEM_REFERENCE_OITEMS (oitemsid) references sa.oitems (oitemsid) on update cascade on delete restrict but got this error: No primary key value for foreign key 'FK_SHIPITEM_REFERENCE_OITEMS' in table 'shipitems' What does it mean and how to round this problem? fyi, here is the definition of both table /*==============================================================*/ /* Table: shipitems */ /*===============================...

Foreign keys have the same columns as primary key
After upgrading from AppModeler 6.0 to 6.1 when I check my PDM I'm getting the following warning messages on a lot of columns: Foreign Keys have the same columns as primary key. The suggested correction doesn't help much. Can some one explain this warning to me? It seems that when the primary key of one table is a foreign key from another table this warning is poping up. Any help appreciated. Thanks, -- James L. Knowlton President and Programer/Analyst Law Enforcement Automated Data Systems, Inc Richmond, VA begin 666 James L. Knowlton.vcf M0D5'24XZ5D-!4D0-&q...

composite primary key and foreign key
I refer a composite primary key of a master table, I have to refer all the fields of the composite primary key. But how to partially refer the composite primary key in a child table? For example, if PARENT table  has primary key (A,B,C), how to create a foreign key in CHILD table which will refer only (A,B) fields of Table1?  Hi, Please refer to the following description: MSDN: In a foreign key reference, a link is created between two tables when the column or columns that hold the primary key value for one table are referenced by the column or columns in another table...

Primary key
> Je me permet de soliciter une aide sur poweramc V8. > Je suis en charge d'un projet ERP et je me pose la question suivante sur un > exemple de mod�lisation. > > Entit� : ARTICLE > information : Code article > Information : Libell� article > > Entit� : Unit� > Information : Code unit� (exemple : Kg, palette, m2...) > information : Libell� unit� > > Un article a 3 unit�s, unit� de stockage, unit� de vente et unit� d'achat. > Ces trois unit�s peuvent �tre diff�rentes. > > Dans mon MCD, j'...

Web resources about - primary key and foreign Key???? - asp.net.sql-datasource

Primary market - Wikipedia, the free encyclopedia
of securities dealers. The process of selling new issues to investors is called underwriting . In the case of a new stock issue , this sale is ...

Primary Health forecasts profit dip - AdelaideNow Search Search
PRIMARY Health Care forecasts underlying EBITDA and net profit after tax for FY2016 to be 5% below last year due to margin compression caused ...

Primary Health forecasts profit dip
PRIMARY Health Care forecasts underlying EBITDA and net profit after tax for FY2016 to be 5% below last year due to margin compression caused ...

David Muir and Martha Raddatz Will Moderate ABC’s Primary Debates
World News Tonight anchor David Muir and ABC’s chief global affairs correspondent Martha Raddatz will moderate two primary debates in the coming ...

“Should refugees have religious freedom?” is now a serious question in the Republican primary
Following the Islamic State’s coordinated attacks in Paris on Friday, blame became a highly-traded commodity. Within hours, conservatives had ...

Polls finds big lead for Van Hollen in Md. Senate primary
... with television advertising, Rep. Chris Van Hollen has opened a significant, double-digit lead in Maryland's closely watched Democratic primary ...

LOSING THE PRIMARY TO WIN THE GENERAL? Why ¡Jeb’s failed campaign hasn’t called it quits
... Bush said early on in his run for president that Republicans need to stop trying to win the argument, and that he would rather lose the primary ...

Even If Trump Disappears From The GOP Primary, There Are Republicans Who Will Support Bernie
... buzz not even 2 months ago about how popular Bernie is with Vermont Republicans and how he's tied with Trump and Carson in the Republican primary ...

New Hampshire Union Leader Endorses Christie for Republican Primary
... Union Leader late on Saturday endorsed New Jersey Governor Chris Christie for the state's first-in-the-nation Republican presidential primary, ...

The Coral announce 'Distance Inbetween,' first LP in 5 years; Bill Ryder-Jones released 'West Kirby County ...
by Bill Pearis The Coral It's been five years since we've heard anything new from The Coral, but they're now back and will release their eighth ...

Resources last updated: 12/1/2015 5:48:06 PM