how to create link between two tables in sql server database

haii

please tell how i can create link between two table suppose:-

i have one table named Contid and another table Contname ,

in Contid it has only one field id and in Contname it has two fields id and name

now what i want to do is when i fetch id from table Contid its corressponding name should be fetched from table Contname, how i can do this please

help 

0
astalavista2007
2/20/2009 7:40:49 AM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

4 Replies
635 Views

Similar Articles

[PageSpeed] 26
Get it on Google Play
Get it on Apple App Store

hi ,

write a sql command for this like below,

select Contid .id,Contname.name from Contid  inner join Contname on Contid .id=Contname.id

After executing this query, you will get what you are looking for


Joydeep Sen
Dotnet Developer

Dont forget to click “Mark as Answer” on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers


0
joydeepsen
2/20/2009 8:33:52 AM

select t1.id,t2.name from table1 t1
inner join table2 t2 on t2.id=t1.id

group by t1.id,t2.name

or

select id,(select name from table2 where id=t1.id)[name] from table1 t1


Mark as Answer if it helped you

Gayathri
0
gayathri
2/20/2009 8:49:23 AM

 Hi,astalavista

I have shown u A example related ur case .Try this

 

create table [Contid]
([id] int )
GO

insert into [Contid]
Select 1
union all
Select 2
union all
Select 3
union all
Select 4
union all
Select 5
union all
Select 6
union all
Select 7
union all
Select 8
GO


create table [Contname]
([id] int ,[name] varchar(20))

GO
insert into [Contname]
Select 1,'Name1'
union all
Select 2,'Name2'
union all
Select 3,'Name3'
union all
Select 4,'Name4'
union all
Select 5,'Name5'
union all
Select 6,'Name6'
union all
Select 7,'Name7'
union all
Select 8,'Name8'

GO



Select [Contname].[name] from [Contname]
inner join [Contid]
on [Contname].[id]=[Contid].[id]

GO

--Output
name
--------------------
Name1
Name2
Name3
Name4
Name5
Name6
Name7
Name8

















--If u want particular Name that is u want to select filter that
--Then u can do that like this 

GO
declare @id int 
Set @id=2

Select [Contname].[name] from [Contname]
inner join [Contid]
on [Contname].[id]=[Contid].[id]
where [Contid].[id]=@id

GO

--Output
name
--------------------
Name2
  
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
2/20/2009 9:03:12 AM

The other answers all presume you are wanting to get your hands dirty in the sql.

Unless you are required to use an old version of asp.net I would recommend using Linq2Sql. If you set up a foreign key relationship between the two tables then you will get this relationship mapped out for free when you make the datacontext.

 

Look into LINQ it will save you hours in the long run!

0
rtpHarry
2/20/2009 9:06:42 AM
Reply:

Similar Artilces:

Link FoxPro Database table to SQL Server Database table
I have LAN Server in witch Visual Foxpro Database reside.I have another remote server in witch SQL Server 2005 installed.I want to link Foxpro table to SQL Server Database Table.Is it possible? Can please someone help? Thanks MS...

I imported a SQL Table into SQL DataBase, But I can not update this table even with SQL Server management Studio
I imported a SQL Table into SQL DataBase, But I can not update this table even with SQL Server management Studio When I change any data on mentioned table above, Red exclamation sign appears left of the record . How can I correct this problem?  Thanks. Try running the UPDATE via Query Analyzer...and see if you get an error.***********************Dinakar NethiLife is short. Enjoy it.***********************...

Why I cannot create/edit tables in VS.Net Server explorer for SQL Server 2000 Developer local database?
I found that when I install MSDE, then I can create/edit database objects for MSDE database in Visual Studio 2003 Server Explorer, but when I try to create/edit database objects under the default database created by the SQL Server 2000 installation, I cannot do these tasks as no option for these tasks appear when I right-click on the database object in Server Explorer.  Anyone knows why this is happening?sun21170 I reproed your issue. And I found in MSDN it is said the Server Explorer can: -Open and view Server Explorer -Add a data connection -Add a server -Drag a...

Creating a SQL Server linked server to Interbase using 64 bit SQL Server
Hi, I am trying to use the data direct odbc driver for interbase to create a linked server in SQL Server 2008 R2 64bit however, SQL Server reports an "Arcitechure Mismatch" between the System DSN and SQL Server. This did work under 32 bit SQL Server. Is there a 64bit specific odbc driver for interbase? I have tried using the IBProvider trial as well but this fails to work in SQL Server as well. Our Interbase client(s) and server are all 64 bit installations. Thank you Julian Dawson wrote: > Is there a 64bit specific odbc driver for interbase? I think Easy...

How to create a copy of SQL Server 2000 database in SQL Server 2005 Express?
I have a database called 'DB1' in SQL Server 2000. I want to create the same database in SQL Server 2005 Express including the original data in tables. How would I do that? I cannot find any option to do this upgrade in SQL Server Management Studio.sun21170 Check out this:How to: Upgrade to SQL Server 2005 with the Copy Database Wizard Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! The article you mentioned does not apply to the 2005 Express Edition. The Management Studio for the Express Edition contains no Copy database opti...

How to enabel sql server notification on database as well as table using sql server 2005
HiI am ASP.NET developer. I have  implemented caching in my site.I am using "System.Web.Caching.SqlCacheDependencyAdmin.EnableNotifications("Data Source=<Data Source name>;Initial Catalog=<database name>User ID=<user id>;pwd=<password>;Pooling=true;Min Pool Size=0;Max Pool Size=1000;") & "SqlCacheDependencyAdmin.EnableTableForNotifications("Data Source=<Data Source name>;Initial Catalog=<database name>User ID=<user id>;pwd=<password>;Pooling=true;Min" Pool Size=0;Max Pool Size=1000;","<tabl...

How to create a data diagram in SQL Server 2005 Management Studio for a SQL Server 2000 database
Hello: I have an old database created in SQL Server 2000, now I can open, access it in SQL Server 2005 Management Studio, but I can't create Data Diagrams. Please advise on how to make it work.... Thank you Expand the database folder in Object Explorer and the first folder under the databases is the "Database Diagrams". Right click -> New database diagram.***********************Dinakar NethiLife is short. Enjoy it.*********************** Thank you for replying :)  but that only works for database created in SQL Server 2005, my database is created in SQL Server ...

New errors access MS SQL Server Database on (CREATE DATABASE and Batch SQL Statement)
------=_NextPart_000_002B_01C2F2CB.0C201FF0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I'm running ActiveState perl 5.8.0 on a WIN2K box with MS SQL Server = 2000. Recently I updated DBD-ODBC to v1.05 and DBI to v1.35 Now I get the following errors executing some sql commands CREATE SQLSTMT:[CREATE DATABASE POMS_SER ON (NAME =3D 'POMS_SER_DAT', = FILENAME =3D 'd:\Database\POMS\POMS_SER_Data.MDF', SIZE =3D 10MB) LOG ON = ( NAME =3D 'POMS_SER_LOG', FILENAME =3D = 'd:\Database\POMS\POMS_S...

SQL Attached mdf database files VS database imported into or created in SQL Server 2005
 Hi all (newbie @ asp.net)(oldie @ ASP 3)What is the purpose of using an attached MDF database files in the App_Data folder on a web site as to importing it into the SQL server directly or creating it on the SQL server. Does a mdf database attached file purely use the SQL server as a connection interface.Is it something similiar to DSN(ODBC) Connections for ms access databases. AFAIK it is only for deployment conveniance, I have always imported the database directly into SQL Server and set up the connection string accordingly.Don't forget to click "Mark as Answer" on the...

Problem with creating new SQL server database in VWDExpress using SQL Server 2005 Express
 when I try to create a SQL Database from Visual Web Developer 2005 Express Edition, I get the following error message: "Connections to SQL Server files (*.mdf) require SQL Server Express 2005 to function properly.  Please verify the installation of the component or download from the URL http://go.microsoft.com/fwlink/?LinkID=49251" When I go to that URL, it brings me to the page to download SQL Server Express 2005. any ideathanks for advance  Did you install SQL Server Express on your server/system? JeffPlease: Don't forget to click "Mark as Answe...

moving an sql server 2005 database to a sql server 2000 database
I am trying to move a database which I wrote in SQL Server 2005 to a SQL Server 2000 database. I'm not sure the best way to do this....... Can anyone enlighten me?.....   this article explains it. http://searchsqlserver.techtarget.com/expert/KnowledgebaseAnswer/0,289625,sid87_gci1149585_tax301536,00.html hth,mcm pizzamaker74: I am trying to move a database which I wrote in SQL Server 2005 to a SQL Server 2000 database. I'm not sure the best way to do this....... Can anyone enlighten me?..... If both are in the same network or box just register the 2005 with the 2000 cr...

Creating a database in SQL Server using an SQL Script
Hi, I am trying to create the "Personal" database in my SQL server using the SQL script (Personal.sql) that is provided with the starter kit.  Does anyone know how I can run this script to create the database? Do I do it from the command line? If so how do I do this and can I use windows authentication to connect to the server? Many thanks in advance, Trevor Keast Hi,      We can run the scripts in two ways. 1. Open your Sql client , if it is sql server 2005 then sql management studio Run-->sqlwb,Sql server 2000 then isqlw. Login to your data...

Create Table syntax SQL in SQL Server 7
Hi guys, I need to pass some SQL to someone else who will run it on their database. I have got the SQL for SQL Server 2000 but they are running SQL Server 7. Apparently the below MSSQL 2000 script doesn't work; SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[tableName]( [id] [int] IDENTITY(1,1) NOT NULL, [ArticleID] [int] NULL, [Heading] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [BodyContent] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [WrittenDate] [datetime] NULL, CONSTRAINT [tableName] PRIMARY KEY CLUSTERED ( [id] ASC )...

Migrating sql server 2005 express database to sql server 2005 database
Hi, I have an application developed using VWD and sqlserver express database. The express database is turning out to be small in size and we need to migrate to larger sqlserver 2005 database. What are the steps for this migration, please list in detail. Regards, Sandyhttp://www.thequinn.infohttp://www.sksdataservices.comhttp://www.infobasket.info Hi Sandy, To move a database from SQL Express to SQL 2005, you can use the following steps. 1. If your database file is attached to the server instance, you will need to detach it first using SQL management studio. If it is under App_Data folde...

Web resources about - how to create link between two tables in sql server database - asp.net.sql-datasource

Database - Wikipedia, the free encyclopedia
A database is an organized collection of data . The data are typically organized to model aspects of reality in a way that supports processes ...

Database - Wikipedia, the free encyclopedia
... requiring information. For example, modelling the availability of rooms in hotels in a way that supports finding a hotel with vacancies. Database ...

ERISA and All Claim databases
... laws, on the books in 18 states, requiring self-insured employers to report data about the prices they pay to “all payer claims databases.” ...

Sanders’ campaign looses access to N.H. Democratic voter database - The Boston Globe Sanders’ campaign ...
... the presidential campaign of US Senator Bernie Sanders has been denied access to the New Hampshire Democratic Party’s valuable voter database ...


Under pressure, DNC restores Bernie Sanders campaign's access to their database - Videos - CBS News
A strange twist in the race for the democratic presidential nomination: the campaign of Vermont Senator Bernie Sanders has filed a complaint ...

Over 680TB of data exposed in MongoDB databases
There are at least 35,000 publicly accessible and insecure MongoDB databases on the Internet, and their number appears to be growing. Combined ...

Change your passwords: NexusMods suffers database breach
... security breach by posts on reddit. Cybersecurity firm REN-ISAC had apparently contacted several university IT departments about a database ...

EFF confirms that the DEA has deleted its phone call database
Earlier this year, it was revealed that the NSA's massive surveillance program had a precursor: the Drug Enforcement Administration's USTO, which ...

MacKeeper Leak Highlights Danger of Misconfigured Databases
The Shodan port-scanning service finds at least 35,000 MongoDB databases accessible without a password.

Resources last updated: 12/20/2015 10:21:37 PM