473,883 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating a Table

How do you create a new table from a SELECT statement of another table
using MS SQL Server. This is part of a distributed database topic for
university. Unfortunately I can only seem to get the new table created
in Oracle and not MS.
Jul 20 '05 #1
4 16492

"Ritchie" <va********@aol .com> wrote in message
news:63******** *************** ***@posting.goo gle.com...
How do you create a new table from a SELECT statement of another table
using MS SQL Server. This is part of a distributed database topic for
university. Unfortunately I can only seem to get the new table created
in Oracle and not MS.


I'm not completely sure, but are you looking for this?

select *
into dbo.NewTable
from dbo.ExistingTab le
where ...

If you want to copy only the structure, you can use "where 1=2". But in both
cases, you get only the columns - no keys, no constraints, no triggers etc.
If you need to copy those as well, then you'll have to recreate them after
creating the new table.

Simon
Jul 20 '05 #2
Thanks Simon, if you are not sure, that leaves me high and dry. I'll try to
explain the objective and see if that helps at all. We have to locate certain
records in a particular table (e.g. locate records by city='London') then
relocate all these records into a new table.

so I guess using
SELECT * FROM oldtable WHERE city='London'
works to gather the necessary records.
We tried CREATE TABLE newtable AS, but this of course is for oracle. So what I
need is the SQL to permit this in MS-SQL

Jul 20 '05 #3

"VARTEGRICH " <va********@aol .com> wrote in message
news:20******** *************** ****@mb-m27.aol.com...
Thanks Simon, if you are not sure, that leaves me high and dry. I'll try to explain the objective and see if that helps at all. We have to locate certain records in a particular table (e.g. locate records by city='London') then
relocate all these records into a new table.

so I guess using
SELECT * FROM oldtable WHERE city='London'
works to gather the necessary records.
We tried CREATE TABLE newtable AS, but this of course is for oracle. So what I need is the SQL to permit this in MS-SQL


Perhaps my previous post wasn't very clear - you can do this:

select *
into dbo.NewTable
from dbo.OldTable
where city = 'London'

That will create NewTable and insert the records you require, but as I said,
it will have no keys, constraints, indexes etc. If you need those, then you
can use Enterprise Manager to generate the CREATE TABLE script for OldTable,
modify the script as needed (change the table name, constraint names etc),
run it to create NewTable and then do this:

insert into dbo.NewTable
select *
from dbo.OldTable
where city = 'London'

Simon
Jul 20 '05 #4
Cheers Simon,
works a treat.
Pity the tutors don't know how to do this though.
Would make life a lot easier.
Thanks Again
Jul 20 '05 #5

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

Similar topics

31
3710
by: Neil | last post by:
I have an Access 2000 MDB with ODBC linked tables to a SQL Server 7 back end. I currently have a selections table in the front end file which the users use to make selections of records. The table has two fields -- primary key (which matches primary key of main, SQL Server table), and a boolean field. The table is linked to the main table in a heterogeneous inner join. I'm looking to move the table to the back end, while still giving each...
7
6670
by: John Baker | last post by:
Hi: I would like to know how to create a temp DB to store the data in a table while I do something else with the table. Specifically, how do I create the temp remove the temp I want to be certain that these are not linked or anything.
1
3412
by: Dixie | last post by:
I wish to add some fields to an existing table in code. I am using the following code from rkc. CurrentDb.Execute ("ALTER TABLE MyTable ADD MyNewField Text 25") This works , but I need to also set the Required, Allow Zero Length and Indexed attributes. I have tried but keep getting a syntax error. Also, can I set the default value of a field in code? Has anyone some examples of these. TIA
8
5973
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1; this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ApplicantName", dataset.Tables.Columns.DataType, 50,
3
4237
by: m3ckon | last post by:
Hi there, I can succesfully create a word doc from my asp.net page, but I have 2 issues I need to resolve in order to use it in my app: 1) Creating a table: I seem unable to create a table, I'm uing the coe below, but I'm unsure as to what the Range parameter should be for oWordDoc.Content.Tables.Add ???
4
24229
by: Coleen | last post by:
Hi All :-) Can anyone give me a URL where I can find a good example of code on how to create a temporary SQL table using VB.net? I've checked the Microsoft site at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm_8_des_04_8jtx.asp which is okay at explaining the process but gives me absolutely no code examples. Unfortunately, I am one of those programmers that can read and
16
10334
by: pukivruki | last post by:
hi, I wish to create a temporary table who's name is dynamic based on the argument. ALTER PROCEDURE . @PID1 VARCHAR(50), @PID2 VARCHAR(50), @TICKET VARCHAR(20)
2
3989
by: astolpho | last post by:
I am using a slightly outdated reference book on J2EE programming. It gives 2 methods of creating a database used in its casestudies. The first is an ANT script that gives the following output: D:\original\CaseStudy-2-5\CaseStudy\Day02\exercise>asant database Buildfile: build.xml env-user: prop-user: set-user:
2
1555
by: djpaul | last post by:
Hello, I have this program and when i want to load pictures it crashes at the form.showdialog()....??? Here it goes: Private Sub CmbPath_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmbPath.SelectedIndexChanged Dim Table As DataTable Dim i As Integer Dim ThumbSize As Integer = 160
6
8019
by: firefighter17103 | last post by:
Hi All, I am new to MS Access 07, & do not know any VB, on a new business adventure. I am running Office07 on Vista Home Premium. I am in the process of creating a database that in the end I will be able to create quotes, bill out customers for security services, cctv products and installs,create purchase orders to my distributors being that I keep no inventory on hand, and track payments such as deposits on equipment. What I need help...
0
9781
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9567
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7960
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5794
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4211
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.