SQL Server - how to create empty table without using create command

Asked By vikram malhotra on 20-Apr-10 11:09 AM
how to create empty table without using create command
tell me
Sagar P replied to vikram malhotra on 20-Apr-10 11:17 AM
I dont think you can create a table without using Create Command.
What you can do is use varible of TABLE type. So you can use it like table in your SP.
You can declare varibale as table type like;

DECLARE @ProductTotals TABLE

(

  ProductID int,

  Revenue money

)


Check out this link for more details;
http://odetocode.com/Articles/365.aspx
Venkat K replied to vikram malhotra on 20-Apr-10 11:53 AM
Yes you can do it using SQL Designer.
Open SSMS --> Expand Database --> Expand Tables
Right click on the Tables --> Select Create Table from context menu

There you can give all the column names and datatypes once you enter all the information right click on the table tab click Save.
That's it!!

Thanks,
Web Star replied to vikram malhotra on 20-Apr-10 01:23 PM
yes u can create table desgin mode if u don't want to create command than just create table in desgin mode or if u want to that stuff within stored proc than best is u can use table variable.
Can you elaborate on why you would such a question? - Robbe Morris replied to vikram malhotra on 20-Apr-10 02:56 PM
What difficulty are you having?  CREATE TABLE is pretty basic SQL used in a variety of flavors (Oracle, SQL Server, etc...).  So, I'm curious why you would ask such a question???
F Cali replied to vikram malhotra on 21-Apr-10 09:07 AM
Your question sounds like a test or interview question for a SQL Server developer.

One way to create an empty table without using the CREATE TABLE command is to use the SELECT INTO command where you copy the structure of an existing table.  Since you want an empty table, just provide a WHERE clause that will alway be false:

SELECT * INTO [dbo].[YourNewEmptyTable] FROM [dbo].[AnotherTable] WHERE 1 = 0

Regards,
http://www.sql-server-helper.com/error-messages/msg-8001-8500.aspx