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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Creating a copy of existing table...

Author  Topic 

kkrishna
Starting Member

23 Posts

Posted - 2009-06-19 : 19:45:37
Hi All,

I am trying to create a copy of the existing table Production.Culture in AdventureWorks database. I have the following code:

USE AdventureWorks;
CREATE TABLE Production.CultureNew
( CultureID(PK,nchar(6),not null)
Name(Name(nvarchar(50)),not null)
ModifiedDate(datetime,not null)
);

The column spec is exactly a copy of the columns in Production.Culture.
When I execute this query, I am getting the error message:

Msg 173, Level 15, State 1, Line 3
The definition for column 'CultureID' must include a data type.

I specified the data type as nchar(6). Why is this error generated?
What should I do further for the data type?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-19 : 20:24:46
use the SSMS, right click on the table and choose "Script Table as CREATE to NEW QUERY Window"
you will the table create script as below

CREATE TABLE [Production].[Culture](
[CultureID] [nchar](6) NOT NULL,
[Name] [dbo].[Name] NOT NULL,
[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Culture_ModifiedDate] DEFAULT (getdate()),
CONSTRAINT [PK_Culture_CultureID] PRIMARY KEY CLUSTERED
(
[CultureID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


then compare with your script and check the CREATE TABLE syntax in the BOL


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-20 : 01:47:48
quote:
Originally posted by kkrishna

Hi All,

I am trying to create a copy of the existing table Production.Culture in AdventureWorks database. I have the following code:

USE AdventureWorks;
CREATE TABLE Production.CultureNew
( CultureID(PK,nchar(6),not null)
Name(Name(nvarchar(50)),not null)
ModifiedDate(datetime,not null)
);

The column spec is exactly a copy of the columns in Production.Culture.
When I execute this query, I am getting the error message:

Msg 173, Level 15, State 1, Line 3
The definition for column 'CultureID' must include a data type.

I specified the data type as nchar(6). Why is this error generated?
What should I do further for the data type?



the syntax you're using is not correct. see below for syntax of create table

http://doc.ddart.net/mssql/sql70/create_7.htm
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2009-06-21 : 19:36:24
Here's an alternate method...

SELECT *
INTO Production.CultureNew
FROM Production.Culture
WHERE 1 = 0 --Comment this row out if you want the data, too!

ALTER TABLE Production.CultureNew
ADD PRIMARY KEY CLUSTERED (CultureID)


--Jeff Moden
"Your lack of planning DOES constitute an emergency on my part... SO PLAN BETTER! "
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row"

For better, quicker answers, click on the following... [url]http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]
Go to Top of Page

kkrishna
Starting Member

23 Posts

Posted - 2009-06-22 : 12:27:06
Thanks, all of you, for the suggestions.
Go to Top of Page
   

- Advertisement -