Showing posts with label thiscreate. Show all posts
Showing posts with label thiscreate. Show all posts

Thursday, March 29, 2012

Create table with 15,000,000 default rows

Hi I want to create a table with one column, which is a identity
column.
Let's say like this:
CREATE TABLE DefaultTable(N int identity(0,1))

Then I want to fill this table with 15,000,000 records, so that I have
a table with the numbers 0 to 14,999,999.

How can I do this as fast as possible. A standard INSERT would take a
long time.

(It can be a temp table or a table variable. I just need a list with
numbered 0 to 15,000,000)

Thank you.

Gidonhttp://www.bizdatasolutions.com/tsql/tblnumbers.asp
--
David Portas
SQL Server MVP
--|||Thanks a lot.

Thursday, March 8, 2012

Create new Table from existing table

Hi

I'm trying to Create a new Table from existing table in Q/Analyzer. I figured it would be something like this:

CREATE TABLE newTable AS
(SELECT * FROM OldTable);

but i keep getting

Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'AS'.

also.. is there another method of doing this, something like

INSERT INTO newTable
(SELECT * FROM OldTable);

and it creates the table ( newTable ) for u if it doenst already exist??

Cheers!!!

im using sql2000

You can try this one:

SELECT

* INTO newTableFROM OldTable|||

The easiest method to copy a table with data is :

SELECT * INTO MyNewTable FROM MyTable

Note: this method does not copy constraints and indexes.

|||

SELECT * INTO will create the table and also transfer the data. If you just want the table structure you can do

SELECT * INTO newTable FROM OldTable WHERE 1=0

You would need to add any constraints/indexes manually.

|||

Thanks for ya help fellas

all helpfull answers

Cheers!!!