Solved

How do I add a surrogate key to a table?

Posted on 2011-09-22
8
737 Views
Last Modified: 2012-06-27
I want to manintain the current Primary Key as below:
 
CONSTRAINT [PK_Time] PRIMARY KEY CLUSTERED
(
      [PK_Date] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
)ON [PRIMARY]
 GO

What is the script to add a surrogate key to this table?
0
Comment
Question by:rhservan
  • 6
  • 2
8 Comments
 
LVL 2

Accepted Solution

by:
marappan earned 500 total points
ID: 36583100
Below is the example for surrogate key:

CREATE NONCLUSTERED INDEX IndexName
    ON TableName (ColumnName);
GO
0
 

Author Comment

by:rhservan
ID: 36583190
The script ran.  How can I verify in the column.  Is there supposed to be another key?
0
 

Author Comment

by:rhservan
ID: 36583319
Please respond to above question and I will award the points. Thanks marappan.
0
 

Author Comment

by:rhservan
ID: 36583410
Please respond to above question and I will award the points. Thanks marappan.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:rhservan
ID: 36583411
Please respond to above question and I will award the points. Thanks marappan.
0
 

Author Comment

by:rhservan
ID: 36583414
Please respond to above question and I will award the points. Thanks marappan.
0
 

Author Comment

by:rhservan
ID: 36583425
Marappan,

Please reengage!!
0
 
LVL 2

Expert Comment

by:marappan
ID: 36587634
Sorry for the delay. I have to modify my solution. Sorry for the confusion.


ALTER TABLE TableName ALTER COLUMN ColumnName IDENTITY (1,1);

Normally surrogate key will be int. So the column you have to choose for surrogate key will be int in the table. If the column does not already exist then add a new column.

I hope this is useful for you. Please let me know if you need more assistance.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Server Log File Space 6 34
sql query 7 37
Create calculation and case in query with times 13 13
Test a query 23 19
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now