Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Scriptin a Create Table

Author  Topic 

tinamiller1
Yak Posting Veteran

78 Posts

Posted - 2012-01-03 : 15:13:28
I want to create a script so it does a create table but want to prmopt the user to enter a table name. This is in SQL Server. Example:

script is as follows:

create table database.dbo.test
(
lastname nvarchar(50),
firstname nvarchar(50),
address nvarchar(50),
city nvarchar(50),
state nvarchar(50),
zip nvarchar(50),
);

This is just an example and NOT actual table info. Cannot provide that as it will violate HIPPA rules. I want the user to be prompted to enter a table name to create because right now there is an actual database name on the server and a dbo but if the users are not careful they will overwrite what is there. I do not want them to have to constantly change the line:

create table database.dbo.test1 every time because they might mess up and overwrite.

Right now the actual information is called
databasename.dbo.claimsQ1

Then I run the bcp to input into this table a gigantic file that houses all of the incoming claims for Q1. If users just run the script as is they will overwrite all the claims in claimsQ1 with the claims from Q2.

I hope I am making sense. Right now the next upload the user would change that top line to
databasename.dbo.claimsQ2 and so on. But I am afraid they might overwrite prior stuff so the only thing I can figure is to comment the create table line out so they have to go in and change the end piece to claimsQ2 for the next go round.

tina m miller

edit: moved to correct forum

tinamiller1
Yak Posting Veteran

78 Posts

Posted - 2012-01-03 : 15:16:28
I know in Access I can prompt for user input so just hoping that it works the same in SQL Server.

tina m miller
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-03 : 15:25:41
You would be hoping incorrectly

EDIT: Access is an application (so is SSMS, but...) and is built to do that.

You COULD (and I can't believe I'm saying this) use Access and connect SQL Server to it

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

tinamiller1
Yak Posting Veteran

78 Posts

Posted - 2012-01-03 : 15:35:49
That is what I thought. I will just comment the first line out and then tell those that are using the script they have to change the table name and then taken comment fields out to ensure past tables are not over written.

tina m miller
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-03 : 15:56:17
WHY Are users loading Tables?

WHY Are you loading Data to Different Table Names?

WHAT if the USer enters a tablename that already exists?

No, they will NOT Just overwrite the table, they will append to it

Without details

Explain your process and what it's for

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -