Normalising Existing Tables
Feb 25, 2008
I've been handed a very old database to knock into shape for an ASP.NET energy monitoring website. The current tables seem to have been created as cross tabs from the meter raw data, and are in the form-
CREATE TABLE [dbo].[PW_Table] (
[Date] [int] NULL ,
[Meter_1] [float] NULL ,
[Meter_2] [float] NULL ,
[Meter_3] [float] NULL ,
[Meter_4] [float] NULL ,
[Meter_5] [float] NULL ,
[Meter_6] [float] NULL ,
[Meter_7] [float] NULL
) ON [PRIMARY]
I'd like to rearrange them into the format-
ReadingID (Identity), ReadingDate (datetime), ReadingValue (float), MeterID (int)
I would set up a lookup table for the Meters and join on MeterID.
Converting the date value from an int into a DateTime is no problem, but I can't work out how to transpose the meter readings. Can anyone point me towards a way of doing this via SQL, or would it need to be done by hand?
Thanks in advance for any help offered.
View 4 Replies
ADVERTISEMENT
Jul 20, 2005
I'm working on an ASP.Net project where I want to test code on a localmachine using a local database as a back-end, and then export it tothe production machine where it uses the hosting provider's SQL Serverdatabase on the back-end. Is there a way to export tables from oneSQL Server database to another in such a way that if a table alreadyexists in the destination database, it will be updated to reflect thechanges to the local table, without existing data in the destinationtable being lost? e.g. suppose I change some tables in my localdatabase by adding new fields. Can I "export" these changes to thedestination database so that the new fields will be added to thedestination tables (and filled in with default values), without losingdata in the destination tables?If I run the DTS Import/Export Wizard that comes with SQL Server andchoose "Copy table(s) and view(s) from the source database" and choosethe tables I want to copy, there is apparently no option *not* to copythe data, and since I don't want to copy the data, that choice doesn'twork. If instead of "Copy table(s) and view(s) from the sourcedatabase", I choose "Copy objects and data between SQL Serverdatabases", then on the following options I can uncheck the "CopyData" box to prevent data being copied. But for the "CreateDestination Objects" choices, I have to uncheck "Drop destinationobjects first" since I don't want to lose the existing data. But whenI uncheck that and try to do the copy, I get collisions between theproperties of the local table and the existing destination table,e.g.:"Table 'wbuser' already has a primary key defined on it."Is there no way to do what I want using the DTS Import/Export Wizard?Can it be done some other way?-Bennett
View 3 Replies
View Related
Sep 22, 2006
hello
I am working with an existing database and there is no Foreign key between 2 tables
how can i create a FK after , when the tables are allready full ?
product :
product_id
report_id
name
report :
report_id
dateR
i want to create a FK on product.report_id, and ON DELETE CASCADE
thank you
View 2 Replies
View Related
Apr 8, 2012
I have three tables :
England_Summer_2001
England_Summer_2002
England_Summer_2003
The tables have the following columns :
Player, Position, [From], [To], Fee, Type, ID, League, Window
I want to create a new table, EnglandFinal with all the data from the three tables although I'm guessing it would not be a good idea to copy the primary keys (ID column) as they would clash.
I have played around with CREATE and INSERT into and UNION but I get various errors. I'm sure I've done this before!
This creates a table from a single table :
select * into Final
from England_Summer_2001
View 14 Replies
View Related
Jun 4, 2007
Hi guys , assuming right now I already create partition function (PF_Date) and partition scheme (PS_Date). Let say I would like to implement the partition on the existing tables ( eg: transaction table which is in PRIMARY filegroup), how am I switch it from PRIMARY to PS_Date ? Is it I have to re-create the particular table then only able to put in the partition scheme? Hope can get any assistance here. Thanks alot.
Best Regards,
Hans
View 8 Replies
View Related
Dec 18, 2006
Hello,
How to add the NOT FOR REPLICATION Option to Existing Tables( IDENTITY column,FOREIGN KEY constraints )- TSQL.
Thanks,
Kanna.
View 5 Replies
View Related
Aug 12, 2005
I need to populate tables in my MS SQL 2000 DB with content from an excel file. I am not sure how this is done or how to format the excel file. If someone could help me with this it would be much appreciated!Thanks!
View 3 Replies
View Related
Mar 23, 2007
Hello Friends,
I am right now working on a project that has a database with over 100 tables in a database. Because of extreme time constraints the developers didn't build in any relationships or constraints between or in the tables. Now I need to remodel the database such that the database is more structured and normalized. I don't have much knowledge about the database design since it is a 2 year old application and the person who developed the database is now gone. I know remodelling the database would require knowledge of the existing database and business rules.
I was wondering if there are any tools that could suggest or discover relationships between tables. For eg. Lets say there are two tables named 'Customer' and 'Order'. I notice that there is a column named 'id' in Customer and a column named 'customer_id' in Order. So I ask the tool to discover a relationship between id and customer_id and it tells me that there is a one-one or one-many or no relationship by comparing values. I heard ERWin would be able to do that but thats expensive. Please do let me know asap.
View 2 Replies
View Related
May 6, 2015
I have been asked to create PK on many tables using a query on all tables where we do not have clustered indexes. Some of the tables contains PK but non-clustered. If in a table there are no PK, then how to decide on which column PK can be created? can we do it with the query without data loss and without human intervention?
View 5 Replies
View Related
Nov 8, 2006
I have a real table with an identity column and a trigger to populate this column.
I need to import / massage data for data loads from a different format, so I have a temp table defined that contains only the columns that are represented in the data file so I can bulk insert.
I then alter this table to add all the other columns so that it reflects all the columns in the real table. I then populate all the values so that this contains the data I need.
I then want to insert into the real table pushing the data from the temp table, however this gives me errors stating that the query returned multiple rows.
I specified all the columns in the insert grouping as well as on the select from the temp table.
ANY thoughts / comments are appreciated. This is beginning to drive me nuts.
Rob
View 5 Replies
View Related
Nov 11, 2014
Is there a method of forcing existing tables into the in-memory filegroup so the table data can benefit from in-memory processing.
View 7 Replies
View Related
Feb 9, 2015
We have an existing BI/DW process that adds large chunks of data daily (~10M rows) to an existing table, as well as using Deletes to remove stale data. This scenario seems to beg for partitioning to support switching in/out data.
After lots of reading on this, I have figured out the mechanics of the switching, bit I still have some unknowns about the indexes needed to support this.
The table currently has several non-clustered indexes, including one on the partitioning column - let's call that column snapshotdate. Fortunately there are no FKs involved, and no constraints.
Most of the partitioning material I see focuses on creating a clustered PK to assist with switching. Not sure if this is actually necessary, but assume I create one using an Identity column (currently missing) plus snapshotdate.
For the other non-clustered, non-unique indexes, can I just add the snapshotdate to the end of the index? i.e. will that satisfy the switching requirement?
View 1 Replies
View Related
May 20, 2015
I normalized the below tables but I am finding it difficult to copy data to the new tables. How do I copy data from existing table to the normalized tables? see the table structure below and other supporting information:
SKU_DATA(SKU,SKU_Description,Department,Buyer) Note: this table already has data in it.
CREATE TABLE SKU_DATA (
SKU
Integer NOT
NULL,
[code].....
The table structure above have two three determinants( SKU,SKU_Description and Buyer). SKU and SKU_Description are candidate keys. Primary key is SKU.
Normalization : SKU_DATA(SKU,SKU_Description, Buyer)
BUYER(Buyer,Department)
View 2 Replies
View Related
Nov 10, 2015
1. I need to make use of in memory engine for my pr-existed develop procedures ,tables ,index. do I need and code changes for application and how to store tables /indexes in OLTP memory
Assume table index may have primary key index as well.
2. If table with one primary index and 2 foreign constraints, 3 non clusters indexed. which one able o load to memory area and how t do that.
3. In memory is lock free zone. usually locks will happpen in RDMS context . how this works without locks.
View 3 Replies
View Related
May 26, 2007
Hello,
Quick question, I hope, I am trying to create a table that has a column that is a nested table in SQL Server 2005 Express Edition. Any ideas how I could go about doing this?
Sincerely,
James Simpson
Straightway Technologies Inc.
View 4 Replies
View Related
Nov 14, 2007
I went to look at the connection string previously entered for a dataset created in a new report, and am not seeing anything intuitive for bringing up the associated datasource dialog box that was used to enter name, type and connection string. I'm also noticing nothing intuitive for deleting an existing dataset. How do you do these two very simple things in an existing project? I dont see the dataset in solution explorer, I see it only in the text box on the data tab and in a limited kind of way on the dataset view where the columns show and maint is allowed mostly on the columns only. I tried hilighting the dataset here and hitting the delete key to no avail.
View 1 Replies
View Related
Aug 13, 2007
Hi All,
I would like to restore database using RESTORE DATABASE ... REPLACE command.
If database exists already and has any open connections this command will fail.
I would like to close all existing connections to specific database before running RESTORE DATABASE ... REPLACE command.
I can do closing from Management Studio using checkbox "Close Existing Connection" when deleting database. Actually I need to do the same but from script.
Please advice me how to do it.
Thanks in advance,
Roman
View 3 Replies
View Related
Feb 18, 2014
I am relatively new to sql developer. There is a new user that just joined our organization. I am trying to grant him the same direct grants privilege to the tables that an existing user has. The existing user has a ton of direct table access privileges and it will take days if I had to do each grant one by one like: grant select,insert,delete,update on 'table name' to 'user id'. Is there a way of copying or inserting an existing user's privilege and granting it to a new user.
View 2 Replies
View Related
Jan 24, 2008
I'm new to my company, although not new to SQL 2005 and I found something interesting. I don't have an ERD yet, and so I was asking a co-worker what table some data was in, they told me a table that is NOT in SQL Server 2005's list of tables, views or synonyms.
I thought that was strange, and so I searched over and over again and still I couldn't find it. Then I did a select statement the table that Access thinks exists and SQL Server does not show and to my shock, the select statement pulled in data!
So how did this happen? How can I find the object in SSMS folder listing of tables/views or whatever and what am I overlooking?
Thanks,
Keith
View 4 Replies
View Related
Dec 7, 2006
We have 20 -30 normalized tables in our dartabase . Also we have 4tables where we store the calculated data fron those normalised tables.The Reason we have these 4 denormalised tables is when we try to dothe calcultion on the fly, our site becomes very slow. So We haveprecalculated and stored it in 4 tables.The Process we use to do the precalcultion, will get do thecalculation and and store it in a temp table. It will compare the thetemp with denormalised tables and insert new rows , delte the old oneans update if any changes.This process take about 20 mins - 60mins. Ittakes long time because in this process we first do the calculationregardless of changes and then do a compare to see what are changed andremove if any rows are deleted, and insert new rowsand update thechanges.Now we like to capture the rows/columns changed in the normalisedtables and do only those chages to the denormalised table , which weare hoping will reduce the processing time by atleast 50%WE have upgraded to SQL SERVER 2005.So We like to use the newtechnology for this process.I have to design the a model to capture the changes and updated onlythose changes.I have the list of normalised tables and te columns which will affectthe end results.I thought of using Triggers or OUTPUT clause to capture the changes.Please help me with the any ideas how to design the new process
View 3 Replies
View Related
Feb 19, 2004
Hi,
I need to create ER diagram from Existing DB2 database into SQL Server 2000.
I'm using System Architect. Please give your advice regarding this.
Thanks,
Ravi
View 1 Replies
View Related
Jan 9, 2006
Hello all
From time to time I receive mssql server databases to export from our customers. Last time I deleted the database files without detaching them. How can I detached them, since I need to atach new ones with the same name?
I'm using MS SQL Server 2003 and the databases are 6.5.
Thank you all.
Regards.
View 7 Replies
View Related
Sep 9, 2007
On executing the DMV dm_exec_session we got 20 connection by user sa.
On futher invetigation we got the below result for user sa
1 BACKGROUND sa . . NULL RESOURCE MONITOR
2 BACKGROUND sa . . NULL LAZY WRITER
3 SUSPENDED sa . . NULL LOG WRITER
4 BACKGROUND sa . . NULL LOCK MONITOR
5 BACKGROUND sa . . master SIGNAL HANDLER
6 sleeping sa . . master TASK MANAGER
7 BACKGROUND sa . . master TRACE QUEUE TASK
8 sleeping sa . . NULL UNKNOWN TOKEN
9 BACKGROUND sa . . master BRKR TASK
10 SUSPENDED sa . . master CHECKPOINT
11 BACKGROUND sa . . master TASK MANAGER
12 BACKGROUND sa . . master BRKR EVENT HNDLR
13 BACKGROUND sa . . master BRKR TASK
14 BACKGROUND sa . . master BRKR TASK
15 sleeping sa . . master TASK MANAGER
16 sleeping sa . . master TASK MANAGER
17 sleeping sa . . master TASK MANAGER
18 sleeping sa . . master TASK MANAGER
19 sleeping sa . . master TASK MANAGER
20 sleeping sa . . master TASK MANAGER
21 sleeping sa . . master TASK MANAGER
I do not understand why sa use to keep there connection.
Canu please help letting me know why sa keep these connections.
Regards
Sufian
View 3 Replies
View Related
Dec 19, 2006
Can SQL Express reside on the same server as MSDE and both run at the same time (different apps)?
I have one app that runs on MSDE and a new to be developed app by a vendor that needs SQL Express.
Thanks
JB
View 1 Replies
View Related
Jun 25, 2007
I am rendering an Association Rules on Report Services. How do I make to filter the word "Existing", just like example below? I want to show attribute name only.
Pneu ML Road = Existing, Sport-100 = Existing -> Road Tubo de Pneu = Existing
to
Pneu ML Road, Sport-100 -> Road Tubo de Pneu
By the way I am using this code:
SELECT NODE_DESCRIPTION,ROUND(NODE_PROBABILITY,2)AS Probabilidade,ROUND(MSOLAP_NODE_SCORE,2)AS Importancia
from [Association].CONTENT
where NODE_TYPE=8
View 3 Replies
View Related
Jul 13, 2006
Hullo!Doubt it matters too much, but I'll just start off by saying that I'm using C# ASP.NET 2.0 in Visual Studio 2005.I currently have a UID field entitled "ID", and I'd like to make it autonumbering so that users can input stuff into it through a simple web interface and not have to worry about the user's ID.Anyone know how I could go about doing this? I can't seem to find a way through VS2005's GUI, and I can't seem to find anything on the internet about doing it through an SQL statement.Thanks!
View 1 Replies
View Related
Jul 26, 2006
Ok, I am trying to teach myself asp.net and sql server. The problem I am having now is I want to update the session that already exists. I have a global session (I think) that is UserEmployeeID, it is inputed when a user selects the select link on the search page which will redirect to an info page. I want to change the employee to a different employee, well I am updating the database well, no that is a lie it doesn’t that is another error, but anyway I try to update it to the new EmployeeID and it will not update…
Partial Class Assignment
Inherits System.Web.UI.Page
Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
Dim empID As Integer
Dim nbrID As Integer
Dim equid As Integer
Dim UpdateQuery
Dim empequipid As SqlCommand
Dim mySQLConnection As String = System.Configuration.ConfigurationManager.ConnectionStrings("DBConnectionString").ToString
Dim myConnection As New SqlConnection(mySQLConnection)
myConnection.Open()
empID = CType(Session("UserEmployeeID"), Integer)
equid = CType(Session("UserEquipID"), Integer)
If CType(empID, Integer) = Nothing Then
empID = (DropDownList1.SelectedValue)
Response.Write("Insert: " & empID)
'Response.End()
Me.SqlDataSource1.InsertCommand = "INSERT INTO [EMPLOYEES_EQUIP] ([EquipID], [EmployeeID]) VALUES " & equid & " " & empID & ""
Me.SqlDataSource1.InsertCommand = SqlDataSourceCommandType.Text
Me.SqlDataSource1.Insert()
Else
empequipid = New SqlCommand("Select EmpEquipID From EMPLOYEES_EQUIP Where EmployeeID = " & empID & " AND EquipID = " & equid & " ", myConnection)
empequipid.CommandType = CommandType.Text
nbrID = empequipid.ExecuteScalar
' Response.Write("Select EmpEquipID: " & nbrID)
empID = (DropDownList1.SelectedValue)
'Response.Write("<br>Update EmployeeID: " & empID)
Me.SqlDataSource1.UpdateCommand = "UPDATE EMPLOYEES_EQUIP SET EmployeeID = " & empID & " WHERE EmpEquipID = " & nbrID & " "
Me.SqlDataSource1.UpdateCommand = SqlDataSourceCommandType.Text
Me.SqlDataSource1.Update()
UpdateQuery = "UPDATE EMPLOYEES_EQUIP SET EmployeeID = " & empID & " WHERE EmpEquipID = " & nbrID & " "
'Response.Write(UpdateQuery)
'Response.End()
End If
Session("UserEployeeID") = (DropDownList1.SelectedValue)
'Response.Write("<br>UserEmployeeID Session: " & Session("UserEmployeeID"))
'-- Turn On Results Table
resultstable.Visible = True
'-- Hide Form by hiding table.
maintable.Visible = False
'clientSearch.Visible = False
End Sub
End Class
I am also getting an error at Me.SqlDataSource1.Update() saying incorrect syntax near ‘0’ but there isn’t a 0??? I am confused…
View 1 Replies
View Related
May 28, 2007
I want to move an existing table from another.
Example
B.mdf dbo.xx to C.mdf dbo.xx
B.mdf dbo.xx has records - I created a script and install the script for C.mdf dbo.xx
C.mdf dbo.xx is empty -
All I need now is to populate the records from B.mdf dbo.xx to the empty C.mdf dbo.xx
I was telling I could do a cut and paste to copy the dbo.xx
Thank you in advance.
~ Peaches ~
View 4 Replies
View Related
Oct 12, 2007
Hi
Anyone Knows
I want to store SQL 2005 Existing Database into SQL Server Through .Net.if i give Database Name in .Net and that Database automatically stored in SQL Server 2005.P(including that Existing Database Tables and Stored Procedures).Please Help me.
Tamil
View 2 Replies
View Related
Oct 23, 2007
Bottom is my table structure. please some one can give me the sql code to add 3 days to the existing date.
SemesterID intSemesterLongID varcharSemesterIdentifier charSemesterIdentifierName varcharSemesterName varcharSemesterStart datetimeSemesterEnd datetimeSemesterNameAlt varcharEnrollmentDeadline datetimeRegistrationStart datetimeRegistrationEnd datetimeLengthInWeeks varcharBulletinStartDate datetimeBulletinEndDate datetimeClassroomStartDate datetimeClassroomEndDate datetimeFacClassStartDate datetimeFacClassEndDate datetimePlanningStart datetimePlanningEnd datetimeGoToTeach datetimeTOButAppears datetimeTOButDisappears datetimeSignature datetimeTOButDue datetimeBookListDue datetimeProfAccess datetimeExamDue datetimeSCGDue datetimeGradesDue datetimeExtGradesDue datetimeTOExt datetimeSessionPlanning datetimeTODue datetimeSCGStart datetimeTOExpire datetimeSRPTOCDue datetimeSRPCopyDue datetimeSRPCCCFormDue datetimeTOID intSemesterIdentifierID intCode varcharTitleIVDescription varcharCreatedBy varcharModifiedBy varcharDateCreated datetimeDateModified datetime
View 1 Replies
View Related
Nov 28, 2007
Hi everyone,How do I set a primary key on an existing column using SQL statements? I have column persID of type int in table employees. How do I correctly apply the ALTER command to change persID type to INT IDENTITY(1,1) NOT NULL? Thanks in advance
View 5 Replies
View Related
Dec 13, 2007
hi,
is there someway I can use to copy an existing stored procedures to another database?
Thanks!
View 5 Replies
View Related
Nov 1, 1999
Hi All,
In SQL 6.5 ISQL, you can click on 'open folder' icon and specify an existing SQL script, open it, edit and execute.
But in SQL 7.0, I don't see a similar feature. I can only open my old sql script with Notepad, copy and paste it in ISQL 7.0.
Any idea?
Thanks
David Nguyen
View 2 Replies
View Related