Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello.......
i have a table named as 'floattable' contains columns as follows:-

id int,
s95id varchar(10)
tagname varchar(10)
tagvalue varchar(10)

and i want to make primary key of two columns (id,s95) by combining them.plz give perfect query.
Posted

CREATE TABLE flotable
(
id int,
s95id varchar(10),
tagname varchar(10),
tagvalue varchar(10),
PRIMARY KEY(id,s95id)
)
 
Share this answer
 
Comments
TAUSEEF KALDANE 17-Feb-14 4:01am    
and how do i refer this key in another table?
how do i create foreign key by referring this primary key?
SQL
ALTER TABLE floattable
   ADD CONSTRAINT PK_FloatTableID PRIMARY KEY (id, s95id)
 
Share this answer
 
Hi You can have a Composite Primary Key which is a primary key made from two or more columns. For example:

CREATE TABLE userdata (
id integer,
s95id varchar(200),,
tagname varchar(200),
tagvalue varchar(200),
primary key (id , s95id )
);

if above not work try to use both data type as integer.

try this link

http://stackoverflow.com/questions/217945/can-i-have-multiple-primary-keys-in-a-single-table[^]

http://www.tutorialspoint.com/sql/sql-primary-key.htm[^]


[^]

Regards
Aravind
 
Share this answer
 
SQL
CREATE TABLE flotable
(
id int not null,
s95id int not null,
tagname varchar(10),
tagvalue varchar(10),

PRIMARY KEY (id,s95id),
CONSTRAINT fk_PerOrders FOREIGN KEY (id)
REFERENCES DimAccount(accountkey)
)
 
Share this answer
 
you can to individually refer the keys for foreign key in other table.
by 'references' clause
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900