Click here to Skip to main content
15,892,537 members
Home / Discussions / Database
   

Database

 
GeneralMaking Multiple "Copies" of a Database Pin
Brendan Vogt16-Mar-08 0:42
Brendan Vogt16-Mar-08 0:42 
GeneralRe: Making Multiple "Copies" of a Database Pin
pmarfleet16-Mar-08 0:47
pmarfleet16-Mar-08 0:47 
AnswerRe: Making Multiple "Copies" of a Database Pin
Brendan Vogt16-Mar-08 0:53
Brendan Vogt16-Mar-08 0:53 
QuestionRe: Making Multiple "Copies" of a Database Pin
Brendan Vogt16-Mar-08 1:00
Brendan Vogt16-Mar-08 1:00 
GeneralRe: Making Multiple "Copies" of a Database Pin
pmarfleet16-Mar-08 1:50
pmarfleet16-Mar-08 1:50 
GeneralRe: Making Multiple "Copies" of a Database Pin
Syed Mehroz Alam18-Mar-08 9:47
Syed Mehroz Alam18-Mar-08 9:47 
Questionhow to ON/OFF identity field through sql script? Pin
combo_ci15-Mar-08 23:48
combo_ci15-Mar-08 23:48 
AnswerRe: how to ON/OFF identity field through sql script? Pin
Mark J. Miller17-Mar-08 4:40
Mark J. Miller17-Mar-08 4:40 
Not quite clear on what it is you are trying to do, but it isn't allowed. I've included the ALTER COLUMN description from BOL below.

If you need to perform this kind of change you'll need to create a table which matches your customers table (MyCustomers_copy) AND has the new definition for the identity column. Then you'll need to copy all the data from the customers table to the copy table. Then drop the original customers table and rename (sp_rename stored procedure) the copy table to the name of the original customers table.

If all you're trying to do is insert an explicit identity value instead of letting SQL Server do it for you, then you just need to use IDENTITY_INSERT
<br />
SET IDENTITY_INSERT MyCustomers ON<br />
<br />
INSERT INTO MyCustomers(CustID, CompanyName) VALUES(202, 'A. Datum Corporation')<br />
<br />
SET IDENTITY_INSERT MyCustomers OFF<br />
<br />


That will allow you to insert any value you like for CustID. However, if the value already exists you'll get a primary key violation error. Usually this is not used from application code, only for coping data from one database to another.

ALTER TABLE Documentation from BOL:

ALTER COLUMN
Specifies that the named column is to be changed or altered. ALTER COLUMN is not allowed if the compatibility level is 65 or lower. For more information, see sp_dbcmptlevel (Transact-SQL).

The altered column cannot be any one of the following:

A column with a timestamp data type.


The ROWGUIDCOL for the table.


A computed column or used in a computed column.


Used in an index, unless the column is a varchar, nvarchar, or varbinary data type, the data type is not changed, and the new size is equal to or larger than the old size.


Used in statistics generated by the CREATE STATISTICS statement. First, remove the statistics using the DROP STATISTICS statement. Statistics that are automatically generated by the query optimizer are automatically dropped by ALTER COLUMN.


Used in a PRIMARY KEY or [FOREIGN KEY] REFERENCES constraint.


Used in a CHECK or UNIQUE constraint. However, changing the length of a variable-length column used in a CHECK or UNIQUE constraint is allowed.


Associated with a default definition. However, the length, precision, or scale of a column can be changed if the data type is not changed.

The data type of text, ntext and image columns can be changed only in the following ways:


text to varchar(max), nvarchar(max), or xml


ntext to varchar(max), nvarchar(max), or xml


image to varbinary(max)


Some data type changes may cause a change in the data. For example, changing an nchar or nvarchar column to char or varchar may cause the conversion of extended characters. For more information, see CAST and CONVERT (Transact-SQL). Reducing the precision or scale of a column may cause data truncation.

The data type of a column of a partitioned table cannot be changed.


GeneralJet DB Error on Windows 2000 [modified] Pin
Dr.Walt Fair, PE15-Mar-08 15:26
professionalDr.Walt Fair, PE15-Mar-08 15:26 
AnswerRe: Jet DB Error on Windows 2000 Pin
Dr.Walt Fair, PE17-Mar-08 5:12
professionalDr.Walt Fair, PE17-Mar-08 5:12 
GeneralNeed to execute a very time consuming Stored procedure on a remote machine. Pin
Rocky#15-Mar-08 1:10
Rocky#15-Mar-08 1:10 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Paul Conrad15-Mar-08 8:03
professionalPaul Conrad15-Mar-08 8:03 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Rocky#16-Mar-08 21:28
Rocky#16-Mar-08 21:28 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Krish - KP16-Mar-08 23:06
Krish - KP16-Mar-08 23:06 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Rocky#17-Mar-08 0:03
Rocky#17-Mar-08 0:03 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Mark J. Miller17-Mar-08 4:43
Mark J. Miller17-Mar-08 4:43 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Rocky#17-Mar-08 6:03
Rocky#17-Mar-08 6:03 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Mark J. Miller17-Mar-08 6:13
Mark J. Miller17-Mar-08 6:13 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Rocky#17-Mar-08 6:18
Rocky#17-Mar-08 6:18 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Mark J. Miller17-Mar-08 6:34
Mark J. Miller17-Mar-08 6:34 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Rocky#17-Mar-08 6:46
Rocky#17-Mar-08 6:46 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Mark J. Miller17-Mar-08 6:56
Mark J. Miller17-Mar-08 6:56 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Rocky#17-Mar-08 7:11
Rocky#17-Mar-08 7:11 
Questionavoiding 1/1/1900 in SQL SERVER? Pin
John Sundar14-Mar-08 23:03
John Sundar14-Mar-08 23:03 
GeneralRe: avoiding 1/1/1900 in SQL SERVER? Pin
Rocky#15-Mar-08 1:06
Rocky#15-Mar-08 1:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.