I am currently setting up a registration system where customers can registers their details and the details of the product, using ASP.net and MS SQL.
There is a column called customerID in the Custoemrs table, and a column of the same name in the Products table, so that I can have relationships between the tables.
For obvious reasons (ie. people that quit half-way through), I want to hold all the information until the end. The ID in the Customer table is unique, and auto-increasing, and therefore not assigned until the data enters the database.
However, I wish to submit information to the Products table at the same time, but what shall I put in for the custoemrID (which hasn't yet been assigned)
If on the source I have a new column, the script generated by SqlPackage.exe recreates the table on the background with moving the data into a temp storage. If the table is big, such approach can cause issues.
Example of the script is below: in the source project I added columns [MyColumn_LINE_1] and [MyColumn_LINE_5].
Is there any way I can make it generating an alter statement instead?
BEGIN TRANSACTION; SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; SET XACT_ABORT ON; CREATE TABLE [dbo].[tmp_ms_xx_MyTable] ( [MyColumn_TYPE_CODE] CHAR (3) NOT NULL,
[Code] ....
The same script is generated regardless the table having data or not, having a clustered or nonclustered PK.
I want to insert a record with fields let say"ProductCode, Name" to a table with records like "ProductCode, Name, NumberofItems". I get mismatching errors "Conversion from string "INSERT INTO dbo.t_Shopping(Productcod" to type 'Double' is not valid.". Note the missing last letter. ProductCode and Name are both varChars, NumberofItems is int in table and double in my code. This is my insertion script ".CommandType = CommandType.Text = "INSERT INTO dbo.t_Shopping(ProductCode, Name, NumberofItems)SELECT ProductCode, Name, @NumberofItems FROM dbo.t_Product WHERE ProductCode=@ProductCode"I have asked this question previously in an other mail, but probably because that thread was marked solved, no one answered.The whole code is like this: I translated some names. I hope its still valid. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim NumberofItems As Double = 1 Dim conn As New SqlConnection("Data Source=DV2SQLEXPRESS;Initial Catalog=testaus;Integrated Security=True") Dim row As DetailsViewRow = DetailsView1.Rows(0) Dim ProductCode As String = row.Cells(1).Text Dim cmd As New Data.SqlClient.SqlCommand Dim param As New SqlParameter() TextBox1.Text = ProductCode With cmd .Connection = conn .CommandType = CommandType.Text = "INSERT INTO dbo.t_Shopping(ProductCode, Name, NumberofItems)SELECT ProductCode, Name, @NumberofItems_ FROM dbo.t_Product WHERE ProductCode=@ProductCode" .Parameters.AddWithValue("@ProductCode", ProductCode) .Parameters.AddWithValue("@NumberofItems", NumberofItems) ' End With Try conn.Open() cmd.ExecuteNonQuery() Catch ex As Data.SqlClient.SqlException Throw New ApplicationException("An error occurred while trying to insert the record") Finally conn.Dispose() End Try RegardsLeif
Is there any way or option to get the all columns of dataset added to table when we add a table in data region. It will take lot of time to add one by one and also there are chances to add one column ore than once.
In SQL Server 2000, I have a parent table with a cascade update to a child table. I want to add a record to the child table whenever I add a table to the parent table. Thanks
Hopefully I am posting this question in the correct forum. I am still learning about SQL 2005. Here is my issue. I have an access db that I archive weekly into and SQL server table. I have used the dst wizard to create an import job and initally that worked fine. field I have as the primary key in the access db cannot be the primary key in the sql table since I archive weekly and that primary key field will be imported several time over. I overcame this initally by not having a primary key in the sql table. This table is strictly for reference. However, now I need to setup a unique field for each of the records in the sql table. What I have done so far is create a recordID field in the sql table that is an int and set as yes to Identify (auotnumber). That worked great and created unique id for all existing records. The problem now is on the import. When I try to import the access table i am getting an error because of the extra field in the sql table, and the error is saying cannot import null value into this field. So... my final question is how can I import the access table into the sql table with one extra field which is the autonumber unique field? Thanks a bunch for any asistance.
I need to add a child table that will tell us who the participants counselor is, what I did was I did a Make Table query based off the primary key of the Parent table and made that the link (foreign key) for the People_tbl and the Counselor_tbl, so if the counselor changes then the user adds the record to the counselor tbl and then puts in the Effective date. The problem is that when I run a report it doesn't show the present counselor always shows the old counselor?
Code: SELECT Student_ind.StudentFirstName, Student_ind.StudentLastName, Student_ind.[Student ID], People_tbl.[Family ID], People_tbl.FirstName, People_tbl.LastName, People_tbl.[Parent ID] FROM People_tbl RIGHT OUTER JOIN Student_ind ON People_tbl.[Family ID] = Student_ind.[Family ID] WHERE (People_tbl.LastName = @Enter_LastName) AND (People_tbl.FirstName = @Enter_FirstName)
I need to see inside a SSIS 2012 project a new SSIS installed component, but in the SSDT 2010 I cannot see the SSIS Data Flow Items tab for adding data source/data destination respect to the choose toolbox items pane.
I need to know what a table's max row Identity is part way thru a data flow. I can't get it at the beginning of the data flow. I need to either (1) add it to the data buffer part way thru or (2) set it into a package variable and then reference the var in a script component.
I've not found a way to add a database column to the data buffer without doing a lookup for each row (too slow and not appropriate here) or some goofy oledb source and then merge join into the data buffer on a contrived join.
I've read questions about referencing package vars in scripts but I can't get that to work. DTS.Variables("varname").Value isn't recognised when I code it up.
Anyone have an idea or solution for either one of these? If you're gonna explain the script code, please include the entire snipet including the INCLUDEs, etc.
I have some website work lined up and it involves some simple modifications to a MS SQL 2000 server. What I'll need to do is add some new data fields and insert some data.
I have some experience with databases - MS Access and MySQL, but I have never used or seen MS SQL 2000. My question is, is this a relatively simple thing to do for someone who hasn't used it before? I can do these things quite simply in Access or MySQL, so is MS SQL 2000 going to be any different?
Also, does anyone know of any free tutorials online that would help me out?
Hi all, I have a database setup with a few rows and i would like to allow a user to create a new row of data. After some googling, I've deduced that I need to somehow use an onclick command to perform an insert command. here is my code as of right now: protected void ItemAdd_Click(object sender, EventArgs e) {int newnum = 4;int POnum = newnum ++;
whenever I run this, I receive the following error and am not sure how to correct it:
System.Data.SqlClient.SqlException: Must declare the scalar variable "@Item".
If someone could please explain to me the process here of what is going ion it would be greatly appreciated. My understanding is the @item is just a variable if you will so i'm not sure why its stating i need to declare it.
Hello all I am new to this site. I am trying to use ASP.NET to build an application but I am not sure how to add photos and other data to the sql table that I have created.
I'm looking for information on how to add indexes to a table in a SQL Server 2000 Database, why add them etc? Any source of good information on the web regarding this?
I have a table size 2078mb, number of row +530,900. Is it normal for sql to lock users out of the db when I add a column to the end of the table? I'm running SQL 7.0. The table has 4 col regular indexes. No primary keys. It locked the user out for about 10 min. I thought with SQL 7.0 this problem went away?
Can I add a column to a database table without dropping and recreating the table?
The problem is that everytime a user creates an action that requires a new table - at the moment I drop the table and recreate the table with the new column.
This requires lots of resources as I have to populate the table again.
I am new to SQL Server 2005 and I am trying to add two fields to an existing table. The table has 15 Million records in it and the save is not completing. How do I add the new fields?
I'm new to SQL server and am in the process of converting an Access Db to SQL.
What I'd like to happen is for the current date and an Autonumber generated as soon as the user enters a value in another field. This was fairly straightforward in Access. When I try to set the default in design table (inSQL), the date() is not available. After a little research I came up with CREATE DEFAULT and Bind column commands, Global variables, etc.
I have a couple of questions for anyone that might know:
Is there an easier way than this to create default values in a table? AND,
Would I also have to bind columns for Table lookups? For example, if I wanted a price to be returned after the product ID was entered (Automatic in Access if relationship/form setup properly), would I have to bind the column? Or would it happen automatically?
The situation is like this,in my Requirements table,my fields are requirement_name,req_id and allow_multiple.allow_multiple.The fiels allow_multiple has a value of 0 and 1.In the Staff table,the fields are staff_id,staff_name,req_id.When we add requirement name to the staff table ot should check for the allow_multiple field, if it is 0 i can only add 1 instance of that requirement to the staff and if it is 1 i can add many instances of that requirement to the staff.How can i do that?
I am new to SQL and have an issue I can not figure out. I have a query with several JOINS, but know my boss is asking for me to add an entire table to my query to view results. Is it possible to add a table to a query with joins? I have tried subquery but I get an EXIST error message. The only way I was able to get the information was join the table and enter every single column to my query. I hope there is an easier and more efficent way of doing this.
Ok What I am looking to do is add http:// to all fields in a table that do not already begin with http://. The query I have come up with so far is the following. However it does not work and I am hopeing that somone that knows what they are doing can give a new guy a hand please.
UPDATE Company SET Company.URL = 'http://' + CompanyURL WHERE Company.CompanyURL IN(SELECT Company.CompanyURL FROM Company GROUP BY Company.CompanyURL HAVING (((NOT LEFT(Company.CompanyURL,7) = 'http://'))))
I have a LIVE SQL 2000 database. I am trying to add some new columns to a table. My question is will I need to take the database off-line to perform this operation? I have replicated it to a sample table if I can't.
I'm using SQL 2005. I want to add a description for each table on my database. How do I do that? I know I can add a description to each field, but how do I add a description to each TABLE? I tried going to Properties but don't see anything.
I trying to add records from a table in DBF format (created with Visual FoxPro) into an SQL table created with SQL Server 2005.
I first converted the dbf file into an ascii file and then in the Query Editor in the SQL Server I typed:
use [c:developesqlsqldatapsw.listener]
append from 'c:developesqldatalistener.txt' type sdf
go
and then I pressed F5. I get an error that says:
Msg 911, Level 16, State 1, Line 1
Could not locate entry in sysdatabases for database 'c:developesqlsqldatapsw.listener'. No entry found with that name. Make sure that the name is entered correctly.
I checked in the directory c:developesqlsqldata and the file psw.mdf is there and when I look in the psw database, the table listener is also there.
Could someone tell me what is going wrong? Also, how do I append the whole dbf table onto an SQL table. there's about 6000 records.
i need to get a answer from your side .i create a ms sql database in table that table itself i already put that field name as image and datatype as image after words i need to add images to that table how
this is going to sound like a ridiculous question, but when you are first adding all your records, do you need to add all the foreign key data yourself so that it ties together?
eg. If studentid =1 in first table, then you need to add record for student id in bridging table so that studentid= 1:teacherid=1 and add teacher id=1 if it is not autoincrementing????
hi i added a new table to my existing database in visual web developernow when i am running this i get an error Invalid object name 'TestTable'.with this sql command string sqlCmd = "INSERT INTO [TestTable] ([Employee], [Client] ,[Project] ,"+ "[TimeSpent],[TimeSpentOnline] ,[Description],[Incident], [Billable],[AfterHours],[Pending],"+ "[OnSite] ,[WorkOrder]) VALUES( '" + employee + "' ,'" + client + "','" + project + "','" + timeSpent + "','" + timeSpentOnline + "','" + desc + "'," + iactive + "," + bactive + "," + ahactive + "," + pactive + "," + osactive + "," + woactive + ")"; but it was working fine i was using this table which is exactly the same thing just a different name ..by the way i didnt create the tracking table string sqlCmd = "INSERT INTO [Tracking] ([Employee], [Client] ,[Project] ,"+ "[TimeSpent],[TimeSpentOnline] ,[Description],[Incident], [Billable],[AfterHours],[Pending],"+ "[OnSite] ,[WorkOrder]) VALUES( '" + employee + "' ,'" + client + "','" + project + "','" + timeSpent + "','" + timeSpentOnline + "','" + desc + "'," + iactive + "," + bactive + "," + ahactive + "," + pactive + "," + osactive + "," + woactive + ")"; i have already double checked the data types and also have made sure that everything was saved properly..... Can any one plz help me out on this
I want to add a computed field to an existing SQL table: where Field1 is >0 and field2 is not null set newfield = 'Y' else set newfield = 'N'
I want to keep this existing table because I'm using it as the basis for an Access Report that is nearly complete.
BTW this table is the result of a DTS package that is comprised of several SQL executables so I need to be able to repeat this as part of a larger process.