Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
kid_on_the_block
Posting Yak Master
172 Posts |
Posted - 2006-02-13 : 22:41:10
|
| Hi How can 2 columns be clubbed together to form a primary key , i mean I have 2 columns job & Batch , need to club them together to form the primary key How is it done I mean in the design , how to define that both the columns togethter form a primary key ,Cause when I go to the table , it allows me to create a PK through the EM only for one column Please help |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-02-13 : 22:45:03
|
| Should try to use Query Analyser to write your create table script. And you can save the create script for future deployment etc.if you are using EM to do this, press and hold the CTRL key while selecting the desired column and right click to set primary key----------------------------------'KH'everything that has a beginning has an end |
 |
|
|
sveroa
Starting Member
14 Posts |
Posted - 2006-02-15 : 05:11:32
|
| This operation might be tricky some times. If you have alot of data you want to keep, it might be best to do this in several steps. I normally use this approach:1) Export table content to a CSV file2) Open the CSV file in Excel and make a new column with the new PK3) Write a formula that combines job and batch columns into an unique PK4) Use "Copy & 'Paste Values' on the new PK-column5) Write an new formula for INSERT statement6) Delete all content of table7) Run the script with the INSERT statements from the Excel file |
 |
|
|
sveroa
Starting Member
14 Posts |
Posted - 2006-02-15 : 05:13:59
|
| And off course, you need to add the new column in the table definition between 6) and 7) |
 |
|
|
|
|
|