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 |
|
cccmtx
Starting Member
4 Posts |
Posted - 2010-12-21 : 12:33:16
|
| Need some help changing a field that is the primary key of the table.This field already contains data between '001 'and '999 ', need to change the data so that they begin to be between '0001 'and '9999'. In short, '001 'will be '0001' and so on ...Thank's in advance. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-12-22 : 05:52:40
|
| select '0'+col from tableMadhivananFailing to plan is Planning to fail |
 |
|
|
jcelko
Esteemed SQL Purist
547 Posts |
Posted - 2010-12-22 : 15:53:26
|
| 1) Learn the differences between a field and a column. IT is important.2) turn off the constraints on the tables in the schema that reference this nameless table. Oh, it is very rude not to post DDL. 3) Use the ALTER statement to change the nameless_key from CHAR(3) to CHAR(4) wherever it appears4) update all those references with a leading '0'5) restore the constraints. Be sure to have CHECK (nameless_key LIKE '[0-9][0-9][0-9][0-9]') in the referenced table.6) Do not expect this to be fast.--CELKO--Books in Celko Series for Morgan-Kaufmann PublishingAnalytics and OLAP in SQLData and Databases: Concepts in Practice Data, Measurements and Standards in SQLSQL for SmartiesSQL Programming Style SQL Puzzles and Answers Thinking in SetsTrees and Hierarchies in SQL |
 |
|
|
|
|
|