i want to create procedure for create table in sql server
2005

for example

create procedure create_table
@table varchar(20)
as
create @table(
id int,
name char(20)
)
but it will get error
what is solution?

Answers were Sorted based on User's Feedback



i want to create procedure for create table in sql server 2005 for example create procedure ..

Answer / saravanan sankar

CREATE PROCEDURE create_table
@table varchar(20)
AS
BEGIN
declare @string varchar(5000)
set @string = 'CREATE TABLE '+ @table +'(id int,name char(20))'
END
exec(@string)


//FIRST RUN PROCEDURE ABOVE AND THEN EXECUTES
EXEC create_table 'TABLE1'

Is This Answer Correct ?    8 Yes 1 No

i want to create procedure for create table in sql server 2005 for example create procedure ..

Answer / pradip jain

create procedure create_table
@table1 varchar(20)
as
Begin

Declare @table table
(
id int,
name char(20)
)
end

If you refer question only syntax error is there!!! as table
variable can not use using create command.

Is This Answer Correct ?    2 Yes 0 No

i want to create procedure for create table in sql server 2005 for example create procedure ..

Answer / monty

hello Saravanan Sankar
thank you for your answer

Is This Answer Correct ?    1 Yes 0 No

i want to create procedure for create table in sql server 2005 for example create procedure ..

Answer / veeresh kethari

Here is the solution...

create proc CREATE_TABLE
@TableName varchar(50)
as
begin
declare @String nvarchar(max)
set @String='create table '+@TableName +'(ID int,Name
varchar(50))'
execute sp_executesql @String
end

Is This Answer Correct ?    1 Yes 0 No

i want to create procedure for create table in sql server 2005 for example create procedure ..

Answer / patan

IF EXISTS (SELECT NAME FROM SYSOBJECTS WHERE NAME = 'PROCEDURENAME')
DROP PROCEDURE PROCEDURENAME
GO
CREATE PROCEDURE PROCEDURENAME
@TEST INT = 0

AS
BEGIN
--HERE CREATING TABLE
DECLARE @CREATE TABLE (ID INT ,NAME VARCHAR(20))

INSERT INTO @CREATE VALUES (1,'PATAN')
.
.
.
.
.
.
END

IN PROCEDURE WE CAN CREATE TABLE AND IT CAN USE THE OUR PROCEDURE @CREATE IS THE TABLE NAME

NOTE:WHILE RUNNING TIME WE CAN CREATE TABLE WITH THERE ALIES NAMES...

THANKS @ GOOD LUCK

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

What is the difference between windows authentication and sql server authentication

7 Answers   HCL,


I have a table Events Events containing cardno,time,id,name- -each id has a cardno my requirement is every day each employee swipe the card several times i want to calculate first and last time of each card the output should be name 1 2 6 7 in out in out holiday holiday xxx 09:30 06:30 09:40 06:45 where 1,2...... are dates for example january 1,2, etc. 6 and 7 are saturday and sunday how it is posssible

0 Answers  


What is a job?

3 Answers  


Can sql servers linked to other servers?

0 Answers  


What is database mirroring?

0 Answers  






What are the steps you will take to improve performance of a poor performing query?

1 Answers   HCL,


What are the main control-of-flow T-SQL constructs?

1 Answers  


How to delete duplicate records from a table?(for suppose in a table we have 1000 Records in that we have 200 duplicate Records , so ,how to findout that duplicate Records , how to delete those Records and arranged into sequence order? one more thing that there is no primary key at all)

5 Answers   Infosys, McAfee,


What is raid, and how it can influence database performance?

0 Answers  


What is a transact-sql statement batch in ms sql server?

0 Answers  


What is GUID in sql server?

0 Answers   BirlaSoft,


What is difference between process and thread? Explain lazy writer funcationality.

2 Answers   Microsoft,


Categories