Results 1 to 8 of 8

Thread: Create table studentinfo select * from studentdata

  1. #1
    Join Date
    Feb 2005
    Location
    Yangon,Myanmar(Burma)
    Posts
    42

    Create table studentinfo select * from studentdata

    hi

    I want to create table like existing one.
    so i wriete statement like that
    Create table studentinfo select * from studentdata
    but i can't.Any idea for it.
    I write it at MS SQL 2000

    Another question
    I installed MSDE only
    I want to attach database using sp_attach_db
    how can i do from Visual Basic?

    Thanks
    pmmw
    Last edited by PMMWAN; 07-07-2005 at 11:49 PM.

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    select * into studentinfo from studentdata

    >>Create table studentinfo select * from studentdata

  3. #3
    Join Date
    Sep 2002
    Posts
    5,938
    You can install sql client tools then connect to msde with query analyzer.

  4. #4
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    MSDE comes to OSQL.exe, you can execute sp_attach_db using OSQL

  5. #5
    Join Date
    Feb 2003
    Posts
    1,048
    Select ... Into has certain issues that you should be aware of. For example, if a column contains all null values, then the select into will fail because SQL will try to creat the new table based on the data in the query result set rather than the underlying schema. This results in it trying to create a field with a size of 0.

    A trick to get around this is to supply it criteria that returns 0 records. This forces SQL Server to look at the underlying schema rather than the data.

    Select * Into studentinfo
    From studentdata
    Where 1 = 2

    Insert Into studentinfo
    Select *
    From studentdata

  6. #6
    Join Date
    Feb 2005
    Location
    Yangon,Myanmar(Burma)
    Posts
    42

    Smile

    Thanks
    it's Good idea writing statement like
    Select * Into studentinfo
    From studentdata
    Where 1 = 2
    It's more safety.

  7. #7
    Join Date
    Sep 2002
    Posts
    5,938
    That only copies schema and data over but not index or keys, you may need recreate them on target table.

  8. #8
    Join Date
    Feb 2005
    Location
    Yangon,Myanmar(Burma)
    Posts
    42
    Thanks
    Good advice from you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •