473,398 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Select * into removes defaults

I have a table, tbl1:
create table tbl1 ([field1] [char] (16) NULL DEFAULT (' '),
[field2] [char] (6) NULL DEFAULT (' ')).

When I do a select * into tbl2 from tbl1, tbl2 does not have defaults.
Is there any settings I have to keep on when I do a select * into?
Any help will be appreciated.
Jul 20 '05 #1
2 1782
On 21 Oct 2004 12:57:02 -0700, Geetha wrote:
I have a table, tbl1:
create table tbl1 ([field1] [char] (16) NULL DEFAULT (' '),
[field2] [char] (6) NULL DEFAULT (' ')).

When I do a select * into tbl2 from tbl1, tbl2 does not have defaults.
Is there any settings I have to keep on when I do a select * into?
Any help will be appreciated.


Hi Geetha,

SELECT ... INTO <tablename> creates a new table and fills it with the data
returned by the SELECT statement (which might come from zero, 1 or many
more tables). It doesn't define any constraints (like PRIMARY KEY, UNIQUE,
FOREIGN KEY, CHECK, NOT NULL) or properties (like DEFAULT or IDENTITY) for
the new table.

You must either create the table with CREATE TABLE first, including all
constraints and properties, then populate it with "INSERT INTO <tablename>
(column list) SELECT ...", or you keep the "SELECT ... INTO <tablename"
and use ALTER TABLE to add the constraints and properties.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2
Thanks, Hugo!

Hugo Kornelis <hugo@pe_NO_rFact.in_SPAM_fo> wrote in message news:<c5********************************@4ax.com>. ..
On 21 Oct 2004 12:57:02 -0700, Geetha wrote:
I have a table, tbl1:
create table tbl1 ([field1] [char] (16) NULL DEFAULT (' '),
[field2] [char] (6) NULL DEFAULT (' ')).

When I do a select * into tbl2 from tbl1, tbl2 does not have defaults.
Is there any settings I have to keep on when I do a select * into?
Any help will be appreciated.


Hi Geetha,

SELECT ... INTO <tablename> creates a new table and fills it with the data
returned by the SELECT statement (which might come from zero, 1 or many
more tables). It doesn't define any constraints (like PRIMARY KEY, UNIQUE,
FOREIGN KEY, CHECK, NOT NULL) or properties (like DEFAULT or IDENTITY) for
the new table.

You must either create the table with CREATE TABLE first, including all
constraints and properties, then populate it with "INSERT INTO <tablename>
(column list) SELECT ...", or you keep the "SELECT ... INTO <tablename"
and use ALTER TABLE to add the constraints and properties.

Best, Hugo

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Frank Natoli | last post by:
Have two tables "abc" and "xyz", where "xyz" is a superset, column-wise, of "abc". Is there any simple way to inject all the rows of "abc" into "xyz"? Tried "insert into xyz select * from abc"...
1
by: Adrian | last post by:
This script works well for searching thru a SELECT list but doesnt work so well with the MULTIPLE option. I need to modify it to work for a SELECT MULTIPLE but I have no idea where to begin, any...
7
by: Hal Vaughan | last post by:
I have a sample script from a book ("Beginning JavaScript" by Paul Wilton) that removes or adds a choice to a <SELECT> element. The <FORM> is form1 and the <SELECT> is theDay. The example uses...
2
by: phpuser32423 | last post by:
Hi everyone Is it by any chance possible to use mysql and php to auto create the content for drop-down lists on forms by retrieving the values from a database? The reason i ask is that on a site...
11
by: Stefan Finzel | last post by:
Hi trying to remove one or all elements of select options fails for Pocket Internet Explorer. Is there a way to do this? if is_PIE { // this does not work on Pocket IE while (opt.length) {...
10
by: serge | last post by:
I am doing a little research on Google about this topic and I ran into this thread: ...
8
by: btober | last post by:
I'm finding that column defaults are not being assigned to nulls when I do an insert by way of a an ON INSERT rule on a view. For example, the following script \set ON_ERROR_STOP ON \c...
10
by: Karsten Hilbert | last post by:
I have the need to output intervals (ages in this case). PostgreSQL takes great care to handle months correctly (eg take into account varying months lengths). This is only possible if either end...
1
by: Nick Spacek | last post by:
Hi everyone, Well, this is a doozy. It doesn't help that I'm using Prototype and scriptaculous either, but here it is: I have two select areas and scripts to transfer items between the two....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.