Creating A Table Programatically!

Nov 25, 2003

Hi SQ Gurus,


Please help me with this issue that I am facing. I want to create a table programatically but want to pass its name as a variable. I would like to do something as follows:


CREATE PROCEDURE BS_Create


(@Name nvarchar(25))


AS


CREATE TABLE [dbo].[@Name](


[ID] [int] IDENTITY (1, 1) NOT NULL ,


[Prod_Name] [nvarchar] (75) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL


) ON [PRIMARY]


GO


The table name is passed in as a parameter. No matter what I pass as a parameter, the table name is '@Name', which is not what I want. Instead, if the variable contains the value 'Product', I would like to see a table with the name 'Product' to be created.





How can I solve this problem.





Any help is appreciated!


Krish Chandra

View 1 Replies


ADVERTISEMENT

Creating An MS SQL Data Table Programatically

Aug 27, 2005

I use Visual Studio and VB.

If I want to create an SQL data table on the server, I go to Server
Explorer and make a small table with the corerct columns. Then I add
rows programatically as needed from the Application I'm working with.

It would suit me, for a current job, to be able to create the table itself programatically.

I don't know how to do this. Can it be done ? If so, could someone give
me a starter, please ? Four cols with a key in the first.

David Morley

View 1 Replies View Related

Problem In Creating A Database Programatically....

Jun 27, 2001

I am crateing the database on the fly using db directory in VC++. I am able to create database. I am also able to create login. These can be easily done by logging as master using the username and password sa and "" resp. Now I want to add a user to the database that i created. but it is being added to the master database. I know that I have to change my login from sa ,"" to the username and password that i gave during login. but i dont know how to change the login. Please help. If you have any code for that then that will be of great help.
Hoping to get a positive response as soon as possible..
Thanx
Nitin Gulati

View 1 Replies View Related

Creating Calculated Members Programatically

Sep 27, 2004

Hi

I've read the MSDN documentation about creating calculated members and states that we can only create session scope or query scope members.

I need to create a static calculated member, one that stays there until it's deletion... That is possibel using Analysis Services, but what about with MDX or DSO?

Thanks in advance

View 1 Replies View Related

Creating Script Task Programatically.

Nov 5, 2007

Hi All,
I am trying to create Script task programmatically. i am struck in one place where we will add the script code. I have given my code.
My Code:

TaskHost taskHost = package.Executables.Add("Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptTask, Microsoft.SqlServer.ScriptTask, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91") as TaskHost;

taskHost.Name = "Create SO";

taskHost.Properties["ReadWriteVariables"].SetValue(taskHost, "User:alesId");

Equvivalent XML code generated by the above code.



Code Block
<DTS:Executable DTS:ExecutableType="Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptTask, Microsoft.SqlServer.ScriptTask, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" DTS:ThreadHint="0">
<DTS:Property DTS:Name="ExecutionLocation">0</< FONT>DTS:Property>

<DTS:Property DTS:Name="ObjectName">Create SO</< FONT>DTS:Property>
<DTS:Property DTS:Name="DTSID">{4498C2BE-58B6-433C-8F3E-0268BD267BAE}</< FONT>DTS:Property>
<DTS:Property DTS:Name="Description"></< FONT>DTS:Property>
<DTS:Property DTS:Name="CreationName">Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptTask, Microsoft.SqlServer.ScriptTask, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91</< FONT>DTS:Property>
<DTS:Property DTS:Name="DisableEventHandlers">0</< FONT>DTS:Property>


<DTS:ObjectData>
<ScriptProject Name="ScriptTask_681442c33ab344b7bedb4492b01245a8" Language="Microsoft Visual Basic .NET" EntryPoint="ScriptMain" SaveBinaries="True" ReadOnlyVariables="" ReadWriteVariables="User::SalesId"/>
</< STRONG>DTS:ObjectData>



Generated XML when done thru SSIS Editor. i have given only the DTSObject..thats where i am struck.



Code Block
<DTS:ObjectData>
<ScriptProject Name="ScriptTask_d17b2b95a3984e37a536f2a6e017e2c9" Language="Microsoft Visual Basic .NET" EntryPoint="ScriptMain" SaveBinaries="True" ReadOnlyVariables="" ReadWriteVariables="User::SalesId">
<ProjectItem Name="dts://Scripts/ScriptTask_d17b2b95a3984e37a536f2a6e017e2c9/ScriptMain.vsaitem">
<![CDATA[' Microsoft SQL Server Integration Services Script Task
' Write scripts using Microsoft Visual Basic
' The ScriptMain class is the entry point of the Script Task.
Imports System
Imports System.Data
Imports System.Math





In the DTSObject, i dont know how to add details thru C# code. Please help me.
Thanks.

View 4 Replies View Related

SQL Sever 2005 - Creating Alias Names Programatically

Aug 14, 2006

Is there a way we can programatically create a SQL server Alias name (SQL 2005 - SQL Native client configuration) using either T-SQL, C# etc. - Manmeet

View 4 Replies View Related

Programatically Creating Dataflow Tasks Require Assembly Reference

Jan 17, 2007

Hi,

I am creating dataflow tasj using following

Imports Microsoft.SqlServer.Dts.Runtime

Imports Microsoft.SqlServer.Dts.Pipeline

Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

These refer to Microsoft.SqlServer.DTSPipelineWrap.dll and Microsoft.SQLServer.DTSRuntimeWrap.dll. While these assemblies were already there in my dev machine I don't find these files in production enviornment for SQL server 2005. I am refering these assemblies from following path in my local machine : C:Program FilesMicrosoft SQL Server90SDKAssemblies.

How to install these assemblies in prod env, offcource one option is to copy it and then put it in GAC thru script . Why does not it gets installed while installation of SQL server 2005. Are these assemly dependent on SP1 ?

Thanks

Mohit

View 4 Replies View Related

Programatically Query Database And Save Report In An Excel Table

May 2, 2007

Hello All,



I am working on constructing a software layer around some features of the RDL language that would allow me to programatically generate reports.



I am reading the RDL specification language, and I do not understand three things:



1) How the DataSet element is populated by the query or more precisely how do the <Field> elements capture all the rows inside the table that is being queries?



To my understanding I wilkl have to define several fields that correspond to all columns of interest in the query.



But that is only for one row (?!) How do the rest of the rows get populated? Does the server recursively create new rows based on my definitions until it matches row for row all the data in the table?



2) Once the elements are inside a DataSet how do make use of that data to render it in a table.



I understand how the DataSource, DataSet, and Table work individually, yet I do not understand how to establish a flow of data between DataSet and Table.



3) Do I even need to use a <Table> as an RDL element in order to organize the data in an excel table?





I would appreciate any help. Thank you!

View 1 Replies View Related

Creating Trigger On Creating Table

Jan 28, 2008



Hi,

If I want to automatically insert a record which has default value in a table,
how can I create the trigger?

View 5 Replies View Related

Difference In Creating Temporary Table By #table And ##table

Nov 29, 2006

Banti writes "IF i create temporary table by using #table and ##table then what is the difference. i found no difference.
pls reply.
first:
create table ##temp
(
name varchar(25),
roll int
)
insert into ##temp values('banti',1)
select * from ##temp
second:
create table #temp
(
name varchar(25),
roll int
)
insert into #temp values('banti',1)
select * from #temp

both works fine , then what is the difference
waiting for ur reply
Banti"

View 1 Replies View Related

Creating A Common Table Expression--temporary Table--using TSQL???

Jul 23, 2005

Using SQL against a DB2 table the 'with' key word is used todynamically create a temporary table with an SQL statement that isretained for the duration of that SQL statement.What is the equivalent to the SQL 'with' using TSQL? If there is notone, what is the TSQL solution to creating a temporary table that isassociated with an SQL statement? Examples would be appreciated.Thank you!!

View 11 Replies View Related

Creating A Table Column That Only Takes Data From Another Table.

May 20, 2006

I am trying to create a table that holds info about a user; with the usual columns for firstName, lastName, etc....  no problem creating the table or it's columns, but how can I "restrict" the values of my State column in the 'users' table so that it only accepts values from the 'states' table?

View 2 Replies View Related

Creating Table Fields Dynamically From Another Table Row

Aug 31, 2006

Hello all:

Is it possible to creates fields of the table dynamically?. I have this situation in my project. This is just a small sample. I have row of length 140. I don't wan't to declare all this fields manually using the create table command.

The description of table is as, in this table all the field are of type varchar only, there are like 140 columns.

create dummy emp (
field1 VARCHAR(100), field2 varchar(200), field3 VARCHAR(100).... )

Table: Dummy
================================================== ==
field1 field2 field3..........
Empid Empname empaage1 sam 23...........
2 rai 22............
.
.
.
n raj 45.............
================================================== ==
Now I want to create another table as "EMP" , with proper data type
fields too..

create table emp (
empid int, empname varchar(100), empage int....)

The table should look like as:

Table: EMP
================================================== ==
Empid Empname empaage............
1 sam 23...............
2 rai 22................
.
.
.
n raj 45.................
================================================== ==

I want to do this dynamically.....
Some how I need to extract those field from table[dummy]; the first row acts as a column header for the table[Emp] and the subsequent row acts as a record for the table[Emp]

A small rough snippet of the code will be appreciated....

Waiting for replies........
saby

View 1 Replies View Related

Creating A Table And Dropping That Table At End Of Execution

Mar 19, 2012

I am using a Stored procedure in which I am creating a table and dropping that table at the end of execution. This SP is calling every 10 second (but no concurrent access) from my application. Is there any issue using the drop table command in the SP? will it create any memory fragmentation issue in SQL server?

View 7 Replies View Related

Creating A Stored Procedure That Will Summarize Data In A Table Into A Table Reflecting Period Data Using An Array Type Field

Sep 20, 2007

I am attempting to create a stored procedure that will launch at report runtime to summarize data in a table into a table that will reflect period data using an array type field. I know how to execute one line but I am not sure how to run the script so that it not only summarizes the data below but also creates and drops the table.

Any help would be greatly appreciated.

Current Table

Project | Task | Category | Fiscal Year | Fiscal Month | Total Hours
---------------------------------------------------------------------------------------------------------
Proj 1 | Task 1 | Cat 1 | 2007 | 01 | 40
Proj 1 | Task 1 | Cat 2 | 2007 | 02 | 20
Proj 1 | Task 1 | Cat 3 | 2007 | 03 | 35
Proj 1 | Task 1 | Cat 1 | 2008 | 01 | 40
Proj 1 | Task 1 | Cat 2 | 2008 | 02 | 40
Proj 1 | Task 1 | Cat 3 | 2008 | 03 | 40

Proposed Table

Project | Task | Category | Fiscal Month 01 | Fiscal Month 02 | Fiscal Month 03 | Fiscal Year
---------------------------------------------------------------------------------------------------------------------------------------------------
Proj 1 | Task 1 | Cat 1 | 40 | 0 | 0 | 2007
Proj 1 | Task 1 | Cat 2 | 0 | 20 | 0 | 2007Proj 1 | Task 1 | Cat 3 | 0 | 0 | 35 | 2007
Proj 1 | Task 1 | Cat 1 | 40 | 0 | 0 | 2008

Proj 1 | Task 1 | Cat 2 | 0 | 40 | 0 | 2008
Proj 1 | Task 1 | Cat 3 | 0 | 0 | 40 | 2008

Thanks,
Mike Misera

View 6 Replies View Related

Creating A Dimension Table From A 3-key Table

Jan 13, 2005

Hi All,

I have a situation with a table that was created for a transactional

system with a 3 columns key. The table is similar to the following:

countrystatecitydescription
11221City A from country 1 and state 12
11321City A from country 1 and state 13
21422City B from country 2 and state 14
21522City B from country 2 and state 15


Now I'm trying to create a dts package that would allow me to build a

city dimension table with unique codes (keys) for each city. What kind of

transformation should I use to translate the old codes (based on the

country-state-city key) into the new ones and preserving the data

integrity?

Thanks,

Ignacio

View 2 Replies View Related

Creating New Table From Existing Table

Apr 20, 2006

Hi,

I m new to this forum with a Query

Create table <table name1 > as select * from <table name2>

this works for oracle. do anybody knows its alternative in sqlserver 2000

thanx. :)

View 4 Replies View Related

Creating Table

Jan 15, 2008

I'm trying to create programmatically a table in my db on sql server 2005.1. I created a string "CREATE TABLE ....." and then tried to execute it using my ADO. That didn't work, so I copied the string into  a query in sql server and got the message "CREATE TABLE sql is not supported". Why's that? 2. I created a stored procedure in my db that will get the "CREATE TABLE...." string and execute it.   I thought it would look something like this:    parameter @createString varchar(MAX)    BEGIN                                                            BEGIN       EXEC @createString           or                             @createString     END                                                                END    Both these options didn't work.How can I make it work properly?Thanks.  

View 3 Replies View Related

Creating A Table

Dec 22, 2003

I need a module to help me create a SQLServer database table. Is there a module that allows users to specify parameters in the creation of a SQLserver table?

View 1 Replies View Related

Creating A Table

May 1, 2000

Hello, folks.

I wonder whether I can create a table based on the script in SQL Analyzer.

If this is possible, can you folks tell me how to do it.

Thanks in advance.

Hyunhyo Jun
GIS Research Group
University of Colorado

View 1 Replies View Related

Creating Table In RAM

Dec 18, 2001

Does anyone know if it is possible to create a tmp table in RAM without pinning it and how to do it? I already knew that SQL has a stored procedure allows pinning a table in RAM.
Thank you for any input.

View 1 Replies View Related

Creating Table

Jul 27, 2006

Hi

I am trying to create a table in sql server 2000 and seem to be getting an error

the code that i am using is as folows:


CREATE TABLE Invoice
(
InvoiceID INT IDENTITY PRIMARY KEY NOT NULL Auto_Increment,
Invoice_no VARCHAR(50),
RefText VARCHAR(50),
CustomerDetails text,
)


I want to be able to have the invoiceid as the primary key that auto increments...

After creating the table id like to import a csv file with only the following data

Invoice_no, RefText, CustomerDetails

is it possible to do this as i want the id to automatically be generated to be unique


thanks

View 6 Replies View Related

Creating Table

Dec 22, 2006

vijay writes "how can i creat a new table as i have in my database"

View 2 Replies View Related

Creating A Table

Jul 20, 2005

How do you create a new table from a SELECT statement of another tableusing MS SQL Server. This is part of a distributed database topic foruniversity. Unfortunately I can only seem to get the new table createdin Oracle and not MS.

View 4 Replies View Related

Creating A Table From .NET

Oct 23, 2006

I need to create tables from a C# code. I made a stored procedure hoping that I will pass a table name as a parameter: @tabName. The procedure executed in SqlServer All Right but when I called it from C# code it created not the table I put in as a parameter but table "tabName." Otherwise everything else was perfect: coumns, etc.

Here is my stored procedure.

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[CreateTableTick]
@tabName varchar(24) = 0
AS
BEGIN
SET NOCOUNT ON;
CREATE TABLE tabName
(
bid float NULL,
ask float NULL,
last float NULL,
volume float NULL,
dateTimed datetime NULL
)
END


What went wrong?

Thank you.

View 6 Replies View Related

Creating Table Problem

Jan 22, 2008

My program is to create temporary table. To avoid creating the same name table, I have to create it dynamically with this code. Random rand = new Random(); string num = "Temp"+rand.Next(100).ToString(); sql = "CREATE TABLE '"+num+"' ( , , , )"; When it is exeucuted, the error message tell it has error near Temp23(num). Is it possible to create table with this way?

View 1 Replies View Related

Creating A Third Table From Two Tables

Apr 7, 2008

Hi All,I will like to create a table from two tables this (explained below) way using a stored procedure. Basically i want the stored procedure to return me the third table but i dont know how to do it.Table ATopicID      Topic ----------------------------- 1               Sometopic 12               Some topic 23               Some topic 34                Some topic 4 Table BRateID     Rate     TopicID---------------------------------------1            5         12            5         13            5         24            4         25            4         36             3         5 Table CTopicID     Topic             Rate--------------------------------------------1            Some topic1        52            Some topic 2      5   3             Some topic 3      5Basically i have a table that stores topics associated with a particular subject. Those topics are stored in table A above. My users can just read the messages associated with the topic and rate that message. The rating is then stored in table B.Now i will like my users to search for topics with a particular word or sentence in table A and the topics that are returned have a rating they specify. My procedure takes the word or sentence to search in table A and and the rating which will be used in table B. I will like to construct another table that has this newly searched results and return it using a stored procedure or anything simple. I dont know how to do this because i have very little knowledge in stored procedures or sql..... Any help(Code) will be greatly appreciated... 

View 11 Replies View Related

Creating A Table Like This(probably 2 PrimaryKeys?)

Jun 4, 2008

Hello there,
I'm going to, by my site, to create the aspnet membership thing.. (you know you can run aspnet_regsql.exe and then its create a lot of tables)But I'm stuck with a table with two primary keys? How the **** is that possible?I got this code to create table:'aspnet_UsersInRolesnonqueryCommand.CommandText = "CREATE TABLE aspnet_UsersInRoles (UserId uniqueidentifier NOT NULL PRIMARY KEY, RoleId uniqueidentifier NOT NULL PRIMARY KEY)"Console.WriteLine(nonqueryCommand.CommandText)Session("Tables") = Session("Tables") + "Number of Rows Affected with table aspnet_UsersInRoles is: " + nonqueryCommand.ExecuteNonQuery().ToString + "<br />"
But you ain't allowed to have two primary keys,How do you then create this table?:
 
Hope for help, and as you probably already has notice is I'm absolutely not expert to this :D
Ps. Tehre shouldn't already be a code for this in vb?

View 8 Replies View Related

Problems Creating A Table

Dec 2, 1999

I have made a database device and a database with SQL Server.
After, I have created some tables and I have made inserts, deletes,
updates, select, etc.
I have 23 tables in my database. Now I'm trying to create a new one,
but I can't. I have this error:

"Unable to allocate new page for database 'ODDO'. There are no more
pages available or valid allocation pages.
Space can be created by droping objetcs, extending the database, or
dumping the log with no_log"

I'm not an expert in SQL Server. Can anybodt help me?
What I have to do?. What is a page?. How can I extend my database?

Thank you very much.

View 1 Replies View Related

Creating Table With Different SCHEMA...

Sep 27, 2005

Hi all,
i m using sql server2005 CTP...i created a database called TEL and in that database i created a user(in security) as
USE [TEL]
GO
/****** Object: User [COLL_DB] Script Date: 09/27/2005 15:38:51 ******/
GO
CREATE USER [COLL_DB] FOR LOGIN [loginName] WITH DEFAULT_SCHEMA=[COLL_DB]

Now,when i m trying to create a table in the database TEL as
CREATE TABLE [COLL_DB].abc (c numeric)
commit;

it gives me error saying
The specified schema name "COLL_DB" either does not exist or you do not have permission to use it.

Now,can someone tell me...what i have to do to fix this error?????????
thanks...

View 1 Replies View Related

Creating Table For A Project

Apr 29, 2012

I am having trouble creating my last table for a project.

I have a table named "Payment".

I have a composite key (ebay_ID & Cellphone_ID).

Would eBay_ID & cellphone_id also be foreign keys since they are the PK of their own table?

I also have an entity called "CC#" and "payment_amt".

For example there is a buyer who purchased 3 diff items, so the ebay_id would be the same and so would the cc#.

View 3 Replies View Related

Creating Table By Variable Name

Feb 16, 2004

Hi
How can i Create a table with variable name
eg
suppose variable x=tab1
I want the table created to be tab1 if x=tab2 then table created shd be tab2.. so how can this be dynamically done(creation of tables as well as stored procs)

i tried : create table @x .. it doesnt seem to work
please help
regards

View 2 Replies View Related

Creating A Blank Table From Another

Feb 17, 2004

Hi again,

I want to create a blank table with the same column names as another but with no rows i.e. it is empty. Does anyone know how to do the last part?

I have so far

create table newtest as select * from shared.test ..... (empty bit here?)

Any good advanced sql tutorial urls would be good to.

Thanks in advance :)

View 12 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved