Board index » delphi » CREATE TABLE vs CREATE TABLE + ALTER TABLE

CREATE TABLE vs CREATE TABLE + ALTER TABLE

Can anybody tell me if there is any difference between creating a table
using a single sentence and creating a table and then altering it to add
primary key and foreign key constraints?

Is the second way less efficient? Has the resulting table any internal
difference that makes it less efficient?

Joan

 

Re:CREATE TABLE vs CREATE TABLE + ALTER TABLE


They should be exactly the same. Often times they are done in different steps
so that data can be bulk inserted without indexes, etc but the two step
process results in the same table. Note that because constraints are ignored
by default during bcp, I guess you could end up with different data allowed in
the table based on how it was loaded.

hth,

Craig Baugh

Quote
Joan Ortanobas <i...@grupo77.es> wrote in message news:86p5lu$quo12@bornews.borland.com...
> Can anybody tell me if there is any difference between creating a table
> using a single sentence and creating a table and then altering it to add
> primary key and foreign key constraints?

> Is the second way less efficient? Has the resulting table any internal
> difference that makes it less efficient?

> Joan

Re:CREATE TABLE vs CREATE TABLE + ALTER TABLE


The best way is to create table using CREATE TABLE sentence and then to
alter it.
When you alter existing table you define specifically name of primary index,
index, constraint and other. In some time by this name you can do following
operations - alter table (add new field in primary key) and according this
changes alter primary key.
Quote
Joan Ortanobas wrote in message <86p5lu$qu...@bornews.borland.com>...
>Can anybody tell me if there is any difference between creating a table
>using a single sentence and creating a table and then altering it to add
>primary key and foreign key constraints?

>Is the second way less efficient? Has the resulting table any internal
>difference that makes it less efficient?

>Joan

Re:CREATE TABLE vs CREATE TABLE + ALTER TABLE


Joan,

The idea behind the ALTER TABLE is that it preserves user permissions. If
you had to alter a table schema by dropping and re-creating the table, then
all the permissions on the table would also be dropped when the table was
dropped.

There is no functionality that I know of, re: the actual table schema
itself, that ALTER TABLE has that CREATE TABLE does not have.

I certainly prefer to get it right the first time when I can, so I always
put all my constraints, etc. in the CREATE TABLE. If after the table is in
use, I discover that I need to change the schema, then I will use ALTER
TABLE.

Quote
Joan Ortanobas <i...@grupo77.es> wrote in message

news:86p5lu$quo12@bornews.borland.com...
Quote
> Can anybody tell me if there is any difference between creating a table
> using a single sentence and creating a table and then altering it to add
> primary key and foreign key constraints?

> Is the second way less efficient? Has the resulting table any internal
> difference that makes it less efficient?

> Joan

Re:CREATE TABLE vs CREATE TABLE + ALTER TABLE


Difference isn't with statements (one or more). Difference is, when
you need to load large amounts of data (for example, migration between
system or to new platform).
When you load data, then after each insert necesassary indexes(primary
key, references, unique) are updated and
checked. I think, when you need to load data, better way is create
table,  load data and then create necessary keys.

Best regards

--
Vents Lauva
vents.la...@ventspils.gov.lv

Quote
"Joan Ortanobas" <i...@grupo77.es> wrote in message

news:86p5lu$quo12@bornews.borland.com...
Quote
> Can anybody tell me if there is any difference between creating a
table
> using a single sentence and creating a table and then altering it to
add
> primary key and foreign key constraints?

> Is the second way less efficient? Has the resulting table any
internal
> difference that makes it less efficient?

> Joan

Other Threads