Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MS SQL Server


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Create Relationship Programmatically


Hi,
I have metadata that stored my table structure and relationship. I would like to know is it possible to create table relationship programatically? Any sample?

Thank you




View Complete Forum Thread with Replies

Related Forum Messages:
How Can I Create A One-to-one Relationship In A SQL Server Management Studio Express Relationship Diagram?
How can I create a one-to-one relationship in a SQL Server Management Studio Express Relationship diagram?

For example:
I have 2 tables, tbl1 and tbl2.

tbl1 has the following columns:
id {uniqueidentifier} as PK
name {nvarchar(50)}

tbl2 has the following columns:
id {uniqueidentifier} as PK
name {nvarchar(50)}
tbl1_id {uniqueidentifier} as FK linked to tbl1.id


If I drag and drop the tbl1.id column to tbl2 I end up with a one-to-many relationship. How do I create a one-to-one relationship instead?

mradlmaier

View Replies !
Trying To Create A Relationship
Here is the error I am getting'role' table saved successfully'users' table- Unable to create relationship 'FK_users_role'.  ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint 'FK_users_role'. The conflict occurred in database 'raintranet', table 'role', column 'role_id'.table rolerole_id intname varchar 50table usersusers_id introle_id inTrying to get table.role_id to be related to role.role_idAny help would be appreciated

View Replies !
How To Create A Relationship?
How do I create a relationship between two tables when the two columns that should connect each table have different names?

i.e. Table Person Column Name       < -- > Table Employee Column Person Name

The two columns actually contain the same data type but different field name and size. I know this involves a series of steps. What are they? Could you please include some sample code.

 

 

View Replies !
Best Way To Create The Relationship
Hi - SQL beginer here....

SQL2005

I have a table dbo.server

Compid - 1
Name PK - Server1
Make - HP
etc...

I have just created a new table dbo.ProcessorInfo with the following columns:

Name
BrandName
ProcessorCoreCount
etc....

This table will have more than 1 record for each name:

Server1 Intel 2
Server1 Intel 2
Server2 Intel 1
Server2 Intel 1

and so on.

What is the best way to relate the name in dbo.server and name in dbo.ProcessorInfo so this is a one to many? Obviously I can't set the name column as a PK as I have more than 1 record of the same value in it.

Help much appreciated!

View Replies !
How To Create A One-to-one Relationship
hello all,
I am new to SQL server and dont have a clue on how to create a one-to-one relationship
in sql server2000. Say, I have a table 'A' with a PK <customer_id> and another table 'B' with a PK <order_id>. Now to define a one-to-one relation between them how to do that?
thanks in advance.

-tanveer

View Replies !
Create SemanticModelObject Programmatically.
 How to create semanticModel Object Programmatically?

View Replies !
Programmatically Create SQLNCLI DSN
Hi all,
 
I need to be able to create a DSN through code that connects to SQL Server using SQL Native Client. I have found the following article: http://support.microsoft.com/kb/q184608/. This demonstrates most of what I need, but it does not show how to set the username and password, which is something that I need to do.
 
Any ideas how I can do this?
 
Regards,
 
Stephen.

View Replies !
Create Trigger For Relationship
Hi,
I need help in creating a trigger before delete. The trigger should be in such a way that it should display a message, if there is any relationship with other table.
 
For example I have a table with employee details which have empid as primary key. I have another table with employee salary details where empid is foreign key. The trigger should check the relationship with these two tables. If I try to delete an emploeyee from employee details table and if there is a relationship of that employee with the salary table then the trigger should print a message. If there is no relationship then the trigger should perform the deletion.
I want to create a trigger like this.
 
Please help!!!!!!!!!!!!!!!!

View Replies !
How Do I Create A Relationship In DB Diagrammer ?
Hi Folks,

When I try to create a Relationship between two Tables I find the Relationship is always created from the Table I start with to itself.

I seem to have to select a Table to enable the Create Relationship option, and then when I 'Add' it creates a recursive Relationship to that Table.

I guess it must be possible to do what I am trying to do ?

I'd appreciate any advice.

Thanks.

Barry

 

 

 

View Replies !
How T Create Relationship B/w Two Tables
Hi
I have two database as Malathi,Indoo
In Malathi database i have

Employee Table AS
----------------------

Eid Int (PK)
Enam varchar(50)


In Indoo Database I have

Job table as

Eid int (FK)
Jid Int (PK)


Now how can i create relation b/w two tables of different database
Any One can help for this query

Malathi Rao

View Replies !
Create Table With Many-to-many Relationship...
Hi, I come back again.
Can anyone help me to create table with many-to-many relationship. Here is my three tables
tbl_Networks
(
NID int identity(1,1) primary key,
NetworkName nvarchar(256)
)

tbl_Categories
(
CID int identity(1,1) primary key,
CateName nvarchar(256),
NID int
)

tbl_Sim
(
SID int identity(1,1) primary key,
NID int,
CID int,
NameOfSim nvarchar(256)
)
My problem is 1 value in tbl_Sim may have multiple values in table tbl_Categories and vice versal. And I don't know how to organise them


So I need some help...

View Replies !
Unable To Create Relationship FK
Hi.
I get this error when i try to create a relationship in a db diagram (sql 2005)
"'tblActivedir' table saved successfully
'tblClient' table
- Unable to create relationship 'FK_tblClient_tblActivedir1'.
Introducing FOREIGN KEY constraint 'FK_tblClient_tblActivedir1' on table 'tblClient' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint. See previous errors."


What i have is 2 tables.
1 named client
1 named activedir

In the client table the columns i want to bind with activedirtable are FR1 and DC1
I want to bind them in the ID of the activedir table (both, in different fk relationships) so that they get the id of activedir.
Fr1 has an fk relationship with activedir (pk is activedir' id)
and DC1 exactly the same in another fk.
So i want both columns to comunicate with activedir.
If p.e. activedir has 3 elements (a,b,c) when i delete element a then werever FR1 or DC1 have this element(binded to it's id) then the element will also be deleted (id of the element) from both FR1 and DC1
I don't want to set Delete and Update action to none because i want the element changed or deleted from activedir, to do the same on Fr1 or DC1 or both.
Any help?
Thanks.

View Replies !
How To Create A New DB On A Remote Server Programmatically?
hi
my domain is hosted on a remote server
related databases are stored on a seperated DataServer
I have the name of that DataServer
and i need to create new DBs programmatically
 
I use this statement on my local machine 
sqlstat= "CREATE DATABASE dbc_" + dbid + " ON PRIMARY" + "(Name=db_" + dbid + ", filename = '" & Server.MapPath("~/app_data") & "" + dbfilename + "')"
but it will not work , because i dont know the physical path
i cant use Server.MapPath()
 
How could i do?
 
thanks

View Replies !
Programmatically Create SqlServer JobSchedule
I wanted to programmatically create SqlServer JobSchedule
The job is to copy data from a particular table in one Database to another table in another DataBaseUser should be able to Schedule/modify Date and Time on which a job is to be executed is to be configured through a UI Screen (WebForm.aspx)
I am using VSStudion2003 ,ASP.net with VB.net with SQL2000 as database .
 
ANY idea on how to do this ?????
Please help me?
Thank u all in advance

View Replies !
Programmatically Create A Lookup Transform
Hi,

i'm creating a Lookup programmatically. But i can't find out how to assign the ConnectionManager that references the lookup data.
Do you have an example for me?

Many thanks in advance.
Stefan L.

View Replies !
Programmatically Create Data Sources
Is there a way to do this? It does not appear as part of the standard SSIS API.

Thanks.

View Replies !
Create SSIS Package Programmatically In VB6
Hi,
 
I am working on modifying a VB6 app that dynamically creates DTS packages to copy data from one database to another depending on the selections made in UI. The project currently uses DTSPackage object library and DTSDataDump Scripting object library.
We are in the process of upgrading the server to SQL 2005. I am exploring the possibility of replacing code that generates DTS packages on the fly with SSIS packages.
 
Is it feasible to do this in VB6 ? I have referred to similar posts which focus mainly on VB.NET or C#.
Any help with white paper or sample code would be appreciated.
 
Thanks in advance

View Replies !
Need To Create &&<Query&&> Statement Programmatically
I am creating a web application that uses a using a web service to get data for my reports.  Since the webservice only accepts 1 parameter called "sql" (the sql select statement), I am using the report's query string to get the data. 

Here is the data source and dataset info I am using:

DataSource
    Name: WebService
    Type: XML
    Connection string: http://localhost/myWeb/myWebService.asmx
    Credentials:  No credentials

DataSet
    Query tab:
       Name: WebService
       Data source: WebService
       Command type: Text
       Query String:   <Query><SoapAction>......</SoapAction></Query>

Here is a sample of the <Query> string that I use when I first build the report:

------------------------------------------------------------------------------

<Query>
 <SoapAction>http://tempuri.org/GetDataset</SoapAction>
  <Method Namespace="http://tempuri.org/" Name="GetDataset">
  <Parameters>
     <Parameter Name="sql" Type="String">
        <DefaultValue>Select * From Customers</DefaultValue>
     </Parameter>

   </Parameters>
   </Method>

 <ElementPath IgnoreNamespaces="true">GetDatasetResponse{}/GetDatasetResult{}/diffgram{}/NewDataSet{}/Results</ElementPath>
</Query>
------------------------------------------------------------------------------
When the user selects a report in the web application, they are prompted for information about the sql statement, and then I can rebuild the <Query> xml fragment, substituting the new sql statemet for the default one.  for example, the statement "Select * From Reports" would be replaced with "Select * From Customers where LN = 'Smith'". 

Then I want to attach that new <Query> statement to the report and run it.  How can I set this information in the report?  I can't find anything that talks about it, but there must be some way!

Thanks in advance for your help!

View Replies !
Programmatically Create A Report Model
Hello,

What we'd like to do is programmatically generate and maintain a report model based on how the individual install is configured. I've found some documentation that makes me believe this is possible, but I'm hoping someone can nudge me in the right direction. The ReportingServices2005 class has several model related methods (CreateModel) and I found the .xsd for the semantic model XML file
(http://schemas.microsoft.com/sqlserver/2004/10/semanticmodeling/SemanticModeling.xsd),
but no real documentation on how to put together a Report Model document from scratch. Looking at the files generated from BIDS is somewhat overwhelming and I have no idea where I'd pull most of the information.


Finally, I want to create Report Model(.smdl) file without Report Model Designer.

I want to Implement CreateModel Method to create new model,  any source code sample..??


  Any help that can be provided would be greatly appreciated. Thanks!


Sandip.

View Replies !
How To Create Report Parameter Programmatically?
Hi,



I'm working on custom report manager. It manages "report entities" and
"report templates" (actually, RDLs uploaded on the server) and stores
one-to-many relation between them. The task is to store
"MasterEntityID" report parameter in every RDL and keep it up in actual
state whether RDL is being assigned to another entity or new RDL is
being uploaded and assigned. I've covered the first issue with
SetReportParameters() web method, but how should I deal with the second
one? Uploaded RDL may be short of the param, so I have to add it
programmatically while uploading.



Thanks,

Anatoly

View Replies !
Create A Relationship In Defirent Databases
Hi,
 Is it possible to create a relationship between to tables in a deferent databases and How to do it from SQL Server Management Server!?
 
Thanks.

View Replies !
How To Create A Datagrid For Two No Relationship Tables
Hi, I am trying to create a create for two table A and table B which have no relationship each time. For TableA, there are 3 columns like ID, APoints1, APoint2. For Table B, there are also 3 columns as ID, Qty, BPoints. There is no internal relationship for these two tables. But there may be same ID inside A and B for some records. Now I want to create a datagrid for displaying the information as :

ID, Sum(A.APoints1 + A.APoints2) - Sum(B.Qty * B.BPoints) WHERE A.ID = B.ID

Please Notice that I can't use directly SQL script as following from table A and table B because there is no relationship for Table A and Table B, otherwise the recult set would be wrong:

Select A.ID, Sum(A.APoints1 + A.APoints2) - Sum(B.Qty * B.BPoints) WHERE A.ID = B.ID group by A.ID


May I know is there solution for it?

Thank you very much!

View Replies !
Create Table With Recursive Relationship
I am fairly new to SQL and I am currently trying to createa SQL table (using Microsoft SQL) that has a recursiverelationship, let me try to explain:I have a piece of Data let's call it "Item" wich may again contain onemore "Items". Now how would I design a set of SQL Tables that arecapable of storing this information?I tried the following two approaches:1.) create a Table "Item" with Column "ItemID" as primary key, somecolums for the Data an Item can store and a Column "ParentItemID". Iset a foreign key for ParentItemID wich links to the primarykey"ItemID" of the same table.2.) create separate Table "Item_ParentItem" that storesItemID-ParentItemID-pairs. Each column has a foreign key linked toprimary key of the "Item" Column "ItemID".In both approaches when I try to delete an Item I get an Exceptionsaying that the DELETE command could not be executed because itviolates a COLUMN REFERENCE constraint. The goal behind these FK_PKrelations is is that when an Item gets deleted, all childItems shouldautomatically be deleted recursively.How is this "standard-problem" usually solved in sql? Or do I inned toimplement the recursive deletion myself using storedprocedures or something ?

View Replies !
Create A View For One-to-many Relationship Table
hi..

I would like to create a view for two tables which have a one-to-many relationship.


Code:


Table: Supplier
Supp_ID
1

Table:Supplier_category
Supp_ID,StockCategoryID
1,56
1,57
1,90



How can i create a view that has columns like below:
Supp_ID, Stock
1,[56,57,90]

Thanks in advance.

View Replies !
How To Use The Create Relationship Function At MS SQL Server
hi all, For those who will celebrate the chinese new year, Gong Xi Fa Cai!!!

I now using microsoft SQL server to manage my database.

To manage the database, I have go through the SQL Server Enterprise Manager
To create my database.

Now I am the stage create the relationship for my relations.

So when I drag the foreign key from one relation to primary key at another
relation, vice versa, it will pop up the 'Create Relationship' form.

What I can saw is there are three check boxes. one check boxes have 2 sub check boxes.
Quote: Checkbox 1 - [Check existing data on creation]
Checkbox 2 - [Enforce relationship for replication]
Checkbox 3 - [Enforce relationship for INSERTs and UPDATEs]
Checkbox 3.1 - [Cascade Update Related Fields]
Checkbox 3.2 - [Cascade Delete Related Records]

Usually the Checkbox 1, 2, 3 had been checked.
but the check box 3.1 and 3.2 is display as uncheck by default.

Another question is when I linked up the relationship between two of the relations will appear
a asterisk(*) beside the relation's name. Why?

But I not very understand to the check boxes means and the asterisk.
Can someone give me some guidelines!!Thanks

Thanks in billions....
Best regards
John Ang

View Replies !
Stored Procedue 2 Create A Relationship.
i have a table where the feilds are
1.fromtable
2.fromfeild
3.fromcategory
4.totable
5.tofeild
6.tocategory.
i have write a stored proceduer for creating 2 relationship between fromfeild & tofeild from the same value in from category & in tocategory.
there r around 465 records in a table.
so anyone can comeout for solution of this.
hope soon i get a solution for this.

View Replies !
Create Or Show Relationship Digram
Dear sir or madam

I have a problem related to create or show relationship digram in sql server 2005. Especially, I want to show relationship diagram that I established in sqlserver 2000 in sql server 2005 but I can't and I don't how to do it.


I look forward to hearing.
Thank you in advance!

Best regard,

seyha moth

View Replies !
Programmatically Create FlatFileSource And OleDB Destination...........
Hi,

I am trying to programmatically in C# create FlatFileSource and OleDB Destination?

I would like your help.... How about column mapping.

I would appreciate your reply.....

 

View Replies !
Programmatically Create A Data Conversion Transformation
Hello,

 

does anyone know of a good example of how to programmatically add a Data Conversion Transformation to a package? I have come so far that I have the component in my dataflow task, but I don't know how to set the properties of it. That is, how to determine the columns that should be converted and to what data type etc.

 

I (as far as I understand) need a data conversion transformation since I have not managed to create (via the designer) a package that reads data from an AS400 via DB2OLEDB and stores it in a SQL Server 2005 Database. I keep getting the error "string cannot be converted from unicode to non-unicode" (or something like that) and by searching this forum I learned that the data conversion component might do the trick.

 

I added this conversion to a manually designed package and it solved the error, but I don't know how to re-create this package programmatically. I would really appreciate some help on this.

 

Also, if someone has managed to import data from AS400 to SQL server 2005 via OLEDB and NOT got the string conversion error, please let me know!

 

Regards,

Annika

View Replies !
How To Programmatically Create SQL 2005 Maintenance Plan
I need to programmatically create a SQL 2005 maintenance plan at hundreds of customer sites.  Each plan will be a little different because of path names, database names, etc., so I can't use one canned plan without modifications.  I know that SQL 2005 maintenance plans are XML packages and SQL jobs, so scripting isn't an option.  I've seen mention of using the .Net API to create the plans, but I can't find any examples.  SMO doesn't seem to have any objects for managing maintenance plans.  Can someone point me to an example of using the API to perform this task?

Thanks,

Tom

View Replies !
How To Create An Excel Connection Manager Programmatically ?
I am following the samples in the online books.  I've got an OLEDB connection manager and source component defined.  I now want to create an Excel connection manager and destination component (see below).  How can I do this? 
 

Dim conMgr As ConnectionManager = package.Connections.Add("OLEDB")

conMgr.ConnectionString = "Provider=SQLOLEDB.1;" "Data Source=FLL-EIS;Initial Catalog=DataLoad;" & _

"Integrated Security=SSPI;"

conMgr.Name = "SSIS Connection Manager for OLE DB"

conMgr.Description = "OLE DB connection to FLL-EIS."

' Create and configure an OLE DB source component.

Dim source As IDTSComponentMetaData90 = dataFlowTask.ComponentMetaDataCollection.New

source.ComponentClassID = "DTSAdapter.OleDbSource"

' Create the design-time instance of the source.

Dim srcDesignTime As CManagedComponentWrapper = source.Instantiate

srcDesignTime.ProvideComponentProperties()

' Assign the connection manager.

source.RuntimeConnectionCollection(0).ConnectionManager = _

DtsConvert.ToConnectionManager90(conMgr)

' Set the custom properties of the source.

srcDesignTime.SetComponentProperty("AccessMode", 2)

srcDesignTime.SetComponentProperty("SqlCommand", Dts.Variables("User::gsQuery").Value.ToString)

' Connect to the data source,

' and then update the metadata for the source.

srcDesignTime.AcquireConnections(Nothing)

srcDesignTime.ReinitializeMetaData()

srcDesignTime.ReleaseConnections()
 
 

' Create and configure an OLE DB destination.   (This is where I need help, as this code does not work)

Dim destination As IDTSComponentMetaData90 = dataFlowTask.ComponentMetaDataCollection.New

destination.ComponentClassID = "DTSAdapter.ExcelDestination"

' Create the design-time instance of the destination.

Dim destDesignTime As CManagedComponentWrapper = destination.Instantiate

' Where can I find documentation about the various ComponentClassIds and Properties???

destDesignTime.ProvideComponentProperties()
destDesignTime.SetComponentProperty("ExcelFilePath", Dts.Variables("User::gsExcelFile").Value.ToString)

destDesignTime.SetComponentProperty("TableName", Dts.Variables("User::gsSheetName").Value.ToString)

View Replies !
Programmatically Create A Report History Snapshot
Hi,

To programmatically invoke a subscription we can use -

exec ReportServer..AddEvent 'TimedSubscription', '575F96C6-A1BD-49FD-9C2F-934FC9658780'

How can we programmatically cause a Manual Report History Snapshot to be created.

I know it can be done using the Webservice. How would we do it using the ReportServer stored procedures. Which SP/SP's can we call. With what parameters.

TIA,

Sam.

View Replies !
Programmatically Create AS2005 Local Cube (C#)
Greetings,
 
Here's what I need to do. I need to programmatically create offline cubes for multiple customers. Using VS2005 (C#) and SQL Server 2000, I am able to do this using the CREATE GLOBAL CUBE command. However, I need to create cubes from SQL Server 2005 as we have upgraded and the CREATE GLOBAL CUBE command does not work as it did before. I've search and found examples using AMO, but they create a server cube. I already have a server cube.
I need to be able to create filtered offline cubes from the existing server cube. I've also read much on XMLA, but that doesn't do it for me either. The code below creates an empty offline cube. However, is there a way to use this to create a cube with data?
I am creating this in a windows application.
 

Server server = new Server();

server.Connect(@"Data Source=C:MyLocalCube.cub");

server.Disconnect();
 
Can anyone help? This is driving me nuts! 

View Replies !
Create Relationship With Tables In A Linked Server
I need to create a relationship between a local table and tables on alinked server. I used the design table wizard and selected therelationship property wizard. In the reslationship property wizard,the tables that I need to get the keys from in the linked server do notshow up. Is there a way to do this, or I simply don't have enoughpermission to tables in the linked server. On the local server, theSecurity tab of linked server property has Local Loging "sa", RemoteUser "sa" and Remote Password "****". Thanks for your help.

View Replies !
Programmatically Create A Report Model SMDL File.
Hello,

 

I'm looking for Programmatically genration of Report Model .smdl file.

 

Please guide me or suggest some links so that ui can refer same.

 

Is there any smdl genrator or any classes for the same...?

 

Thanks in advance.

 

Sandip

 

View Replies !
Create &&amp; Filter AS2005 Local Cube Programmatically
Although I can create the local cube, the cube that is created is very large because it brings over all accounts for the employee. In AS2K, it filtered automatically and only returned accounts that had revenue, which is what I'm trying to do using AS2005. I've read some of the responses about using XMLA and AMO, but I am not sure how to use these within the VS2005 windows application that I use to create and distribute the local cubes. Does anyone have a good example of how to use XMLA, AMO or anything else that would allow me to programmatically create and filter offline cubes using C#?
 
For instance, this code DOES create an empty cube. But how would I go about getting data into this cube?
Server server = new Server();
server.Connect(@"Data Source=c:MyLocalCube.cub");
server.Disconnect();

View Replies !
Run Report Multiple Times Programmatically In Order To Create A Table Of Contents
Hi,

I have been working through how to generate a Table of Contents (page numbers need to be from a pdf format) in the front of a very large price list report.  I am so close to having everything the way I need it. In fact, I can get the desired results by manually doing the following:

1.  Run the report in Report Server - (custom assembly writes the preview page numbers to a TOC database table)

2.  Truncate the database table - (I'm not sure why I have to do this, but it is the only way I can get  the new values created in step 3 to write to the database properly)

3.  Export to pdf in Report Server - (writes the correct pdf page numbers to the TOC table)

4.  Refresh the report in Report Server

5.  Export to pdf again in Report Server.

Of course, I can't ask my users to do this.  I want my users to be able to just do step 5 and get the desired PDF.  I have found several postings and they all say things like "run the reports 3 times", but don't say how to do this, or give any reference web sites or examples.  I know here's a way to do it programmatically, but I'm having a difficult time figuring out how to do it.  I do not want to render the report to the user until the pdf has the correct page numbers in my Table of Contents (step 5).

Any suggestions would be greatly appreciated.

Thanks in advance,
Amy Bolden

View Replies !
Failing To Create Relationship (SQL Server Claims Table Lacks PK For Some Reason ?)
I tried to create a relationship in EM's diagram pane inSQL Server 2000 (I'd list the version of EM, but About gives methe MMC version, which is probably not relevant.)(The database itself is SQL Server 2000 SP3.)I got an error that I don't understand (because, at leastat first blush, it appears to be quite untrue). Note thatI have never clicked before on the diagrams child of thedatabase; this was entirely experimental."Primary key or UNIQUE constraint must be defined fortable 'xxx' before it can participate in a relationship."http://msdn.microsoft.com/library/d...cantbepktbl.asp1) My table already had a primary key; why is MS SQL Server apparentlyclaiming otherwise ? (I don't think I can define a second primary keyon the same table. I could perhaps define an additional unique indexon top of the primary key, but, I'm not sure.)2) What does it mean: table '<0s>' ? That is, what does 0s mean ?

View Replies !
Import Csv Data To Dbo.Tables Via CREATE TABLE &&amp; BUKL INSERT:How To Designate The Primary-Foreign Keys &&amp; Set Up Relationship?
Hi all,
 
I use the following 3 sets of sql code in SQL Server Management Studio Express (SSMSE) to import the csv data/files to 3 dbo.Tables via CREATE TABLE & BUKL INSERT operations:
 
-- ImportCSVprojects.sql --

USE ChemDatabase

GO

CREATE TABLE Projects

(

ProjectID int,

ProjectName nvarchar(25),

LabName nvarchar(25)

);

BULK INSERT dbo.Projects

FROM 'c:myfileProjects.csv'

WITH

(

FIELDTERMINATOR = ',',

ROWTERMINATOR = ''

)

GO
=======================================
-- ImportCSVsamples.sql --

USE ChemDatabase

GO

CREATE TABLE Samples

(

SampleID int,

SampleName nvarchar(25),

Matrix nvarchar(25),

SampleType nvarchar(25),

ChemGroup nvarchar(25),

ProjectID int

);

BULK INSERT dbo.Samples

FROM 'c:myfileSamples.csv'

WITH

(

FIELDTERMINATOR = ',',

ROWTERMINATOR = ''

)

GO
=========================================
-- ImportCSVtestResult.sql --

USE ChemDatabase

GO

CREATE TABLE TestResults

(

AnalyteID int,

AnalyteName nvarchar(25),

Result decimal(9,3),

UnitForConc nvarchar(25),

SampleID int

);

BULK INSERT dbo.TestResults

FROM 'c:myfileLabTests.csv'

WITH

(

FIELDTERMINATOR = ',',

ROWTERMINATOR = ''

)

GO

========================================
The 3 csv files were successfully imported into the ChemDatabase of my SSMSE. 
 
2 questions to ask:
(1)  How can I designate the Primary and Foreign Keys to these 3 dbo Tables?
      Should I do this "designate" thing after the 3 dbo Tables are done or during the "Importing" period?
(2) How can I set up the relationships among these 3 dbo Tables?
 
Please help and advise.
 
Thanks in advance,
Scott Chang
 
  

View Replies !
Why I Got The Message As You Need To Create The Many-to-one Relationship Between The Case Table And The Nested Table?
Hi, all experts here,

 

Thank you very much for your kind attention.

 

I am trying to create a new mining structure with case table and nested table, the case table (fact table) has alread defined the relationships with the nested table(dimension table), and I can see their relationship from the data source view. But why the wizard for creating the new mining structure showed that message? Why is that? And what could I try to fix it?

Hope it is clear for your help.

Thanks a lot for your kind advices and I am looking forward to hearing from you shortly.

With best regards,

Yours sincerely,

 

View Replies !
How To Create SQL Server Express Server (INSTANCENAME) Programmatically?
In deploying SQL Express, how do I create a new server (INSTANCENAME)programmatically?What would be the best approach to accomplish this.Thank you so much,

View Replies !
How To Set A Relationship Here?
How to create a relation between gf_game and gf_gamegenre here? gf_gamegenre is responsible for the relation between a game and it's genre(s). The relationship between gf_genre and gf_gamegenre worked. (http://img361.imageshack.us/my.php?image=relationzl9.jpg)

 When I try to set a relationshop between gamegenre and game I'm getting this error:
'gf_game' table saved successfully'gf_gamegenre' table- Unable to create relationship 'FK_gf_gamegenre_gf_game'.  The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_gf_gamegenre_gf_game". The conflict occurred in database "gamefactor", table "dbo.gf_game", column 'gameID'.
Thanks for any help!

View Replies !
Need Help With Relationship
I have this situation in my DB:
tblClients, ClientID(pk) 1---M tblDocuments, DocumentID(pk), ClientID(fk), DocumentTypeID M---1 tblDocumentTypes, DocumentTypeID(pk)(this is a lookup table)
If a client is deleted I want to cascade and delete that clients documents from tblDocuments. When I set the relationships delete and update to cascade on tblDocuments it is also set to cascade on the lookup table (tblDocumnetTypes).
Why is this and how do I make it stay the way I want it?
 

View Replies !
Many To One Relationship
Hello
 I have need to write a query that I can pass in a bunch of filter criteria, and return 1 result....it's just ALL of the criteria must be matched and a row returned:
 example:
 Transaction table: id, reference
attribute table: attributeid, attribute
 transactionAttribute: attributeid, transactionid
 Example dat
 Attribute table contains: 1 Red, 2 Blue, 3 Green
Transaction table contains: 1 one, 2 two, 3 three
transactionAttribute contains: (1,1), (1,2), (1,3), (2,3), (3,1)
 
If I pass in Red, Blue, Green - I need to be returned "one" only
If I pass in Red - I need to be returned "three" only
If I pass in Red, Green - nothing should be returned as it doesn't EXACTLY match the filter criteria
 
If anyone's able to help that would be wonderful!
Thanks, Paul

View Replies !
How Can I Set A One-to-one Relationship
How can I set a one-to-one relationship using the Management Studio Express and SQL Server 2005 Express
tblClient, CleintID (PK)
tblProcess, ClientID (FK)

View Replies !
One To One Relationship
I created 2 tables with one to one relationship. if I add a record intable A, how does table B record get created? Does SQL do thisautomatically because it is one to one relationship? or do I need tocreate a trigger? if i need a trigger, how do I get the ID of newrecord to create the same ID in table B?thanks for any help.Joe Klein

View Replies !
One-One Relationship
Hi,Do you guys know what's wrong with a one-to-one relationship?The reason I want to make it like this is that at the very end of the chain,the set of keys is huge. I want to limit the number of columns to be thekey. i.e. the [company] table has 1 column as the key. The [employee]table will have 2 columns as the key.e,g,If I add a [sale] table to the [company]-[employee] relationship, the thirdtablewill have 3 columns as the key -- "company id", "employee id", and "saleid".(e.g.)I have a company with many employees and computers. But instead of classifyall these, I just want to call all these as an entity. A company is anentity. An employee is just another entity. etc.So, instead of a one-to-many:[company]---*[employee]---*[sale]||*[computer]I make it one-to-one.[entity]---*[entity]If I want to know the name and address of the entity "employee", I will havea 1-to-1 table [employee] to look up the information for this employeeentity.[entity]---*[entity]||[company]||[employee]||[computer]||[sale]--[color=blue]> There is no answer.> There has not been an answer.> There will not be an answer.> That IS the answer!> And I am screwed.> Deadline was due yesterday.>> There is no point to life.> THAT IS THE POINT.> And we are screwed.> We will run out of oil soon.[/color]

View Replies !
ER Relationship
For a weak relationship, will 0 and 1 in the ER diagram represent partialand total participations of the 2 entities sets respectively or vice versa.

View Replies !
Many To Many Relationship
hi all,
how to implement the many to many relation ship....
i get stucked it.......
plz help
thanx
sajjad

View Replies !
Why Using One-to-One Relationship
Hey,
I know I'm asking a stupid question but I need to get a clear response please:
why using One-to-One relationship instead of meging the 2 tables in only one?
thanks.

View Replies !
ISA Relationship
Hi,
do you use ISA relationship or do you avoid it? Why?
Could you write me some its benefitsand drowback?
Thanks

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved