Inside microsoft sql server database I have table User with column Password. Password is of type varchar(50) and I want to change to varchar(255).
I tried using microsoft sql server management studio and using design view I tried manually to change 50 to 255 but on saving that action I'm getting alert
Following tables will be saved to your database. Do you want to continue?
User
xx
xx
xx
On chosing yes I'm waiting for whole min with mouse cursor busy and I'm getting back
Errors were encountered during the save process. Some database objects were not saved.
User table, Unable to delete relationship FK.....
Timeout expired.
I'm confused since I'm not changing anything but this lenght of Password column.
Is there any simple way to complete this simple operation, change varchar(50) to varchar(255)
When you use the designer to make changes, behind the scenes SSMS generates a huge script that creates a new temporary table, dumps all the data from the old one into the temporary one, deletes the old table and then renames the temporary table back to the name of the original name. It also is smart enough to drop foreign keys, constraints, etc. and then tries to put them all back later. Depending on the complexity of the table the script can be hundreds or thousands of lines long.
Instead, since you're really just asking for a little more space in your column which is keeping the same underlying data type, you could directly alter the data type of the column with a simple two-liner:
ALTER TABLE [dbo].[User]
ALTER COLUMN [Password] varchar(255) NOT NULL
GO
(Adjust the script according to whether the column is nullable, has defaults, etc.)
Of course you should have a backup of the database that table is in before you do any of this. You may also need to drop existing connections to the database. It could be that the script is waiting for exclusive access to the table before it does any work.
Related
I am trying to create a page in C# for editing data in SQL Server, and the data is like title, date, description and that's not a big deal
The problem is each row of this has a foreign key to another table that has image URL so each row has like 3 OR more images.
Like I said before I want to create a page which can edit all of these, I made it with listview but it really really bad so I was trying to find another ideas so can you help me in that
Well, the foreign key isn't that difficult to deal with. When a user edits that FK, before you allow the change to be committed to the cell or saved, run a check against the Db to see if their entry is valid. If it is, allow the edit, if not, cancel their edit of that value.
If that other table is the only table that has a FK to worry about, you could return just the Ids in your initial call and check against the dataset to save some round trips.
I have an ASP.net (C#) application that I am working on. In the application are multiple pages of form fields to be filled out and submitted. At the bottom of the last page is a submit button which writes everything to the databse. The code for writing these fields from form to DB is very complex as there are about 30 different stored procedures being called. I am trying to create a duplicate when a user clicks on a new button called "replicate", which SHOULD store a duplicate copy in the DB. I try to copy paste the code for write to DB from the "submit" button but I get a bunch of problems. I have tried a lot of different approaches such as pasting the submit button's code in a new method and from the "replicate" button call that method but this approach doesn't work. So, I am confused as to whether there is an easier way to duplicate the submitted copy that is being stored in the DB. Normally a couple SQL statements would work but in this case there are about 35 stored procedures, 70 SQL tables, and 425 columns, which is a problem.
So basically a summary of the problem is:
I have a form that on submit, writes the filled fields into various locations in the DB, depending on what the field is.
I would like to create a "replicate" button that duplicates the DB stored fields of the form creating a duplicate copy.
Issue: As I stated there are about 215 form fields and 70 SQL tables, each form field going into a certain column in the table.
I would go about this by creating one more stored procedure which does the copying directly in the database. Then you could have your "Replicate" button call the new stored procedure which creates the copy and returns some handle (some base id value created for the copy) and use the handle to load the copied version into the application. Make sure to run the copying inside a transaction so you either get a complete copy to commit or can rollback if some error occurred.
I dragged a view onto my dbml file and I am retrieving records from it. Upon modifying the records and calling context.SubmitChanges() no changes are sent back to the database. Upon debugging I saw that my context.ViewName.IsReadOnly is true.
Is there any way to change this? I can run sql update statements just fine in SSMS against the view, so I am unaware of why this wouldn't be possible.
Manually identifying the primary key in the dbml worked for me - just select the field that is mapped to the primary key from the source table and in its properties change 'Primary Key' to true.
I am writing my first database application in c# and I have to use MS Access database, I have two tables Invoice and Order the order table is a child table. Invoice is a parent table it has key column "InvoiceNumber" which is auto column and it has a one to many relation with Order table column "InvoiceNumber". The problem I am having is that I got an exception at the line
tableAdapterManager.UpdateAll(database1DataSet);
when I try to add a new row and click save,
"You cannot add or change a record because a related record is required in table 'Invoice'."
I tried to search but I am unable to find it any help for ms access database, most of them are of SQL database. I also found one solution to edit the relation in the dataset designer to select the option "Both relation and foreign key constraints" but it didnot work for me either.
Thanks
Make sure that your OleDbParameters are properly set and in the correct corresponding order as the columns in the tables in the database. If you use Visual Studio automated code generation for data sources when you add a database, then drag and drop a table onto a form, check out the <database name>DataSet.Designer.cs file. It will teach you all you need to know.
What does this icon mean is Visual studio, visual Data Set designer.
I have several stored procedures.
can you help me understand,
why the one on top of the list has a
small "check mark"
why I can't delete it if I need to.
This is not the case with the rest.
Why is this "special" ?
Thanks
Because that item contains the method(s) that define the schema of the table the TableAdapter is part of.
The default names are Fill and GetData. Looks like you renamed them.
Each table has a default query (The one on top with the check on it). When you dragged your tables in to the dataset to create the query, it wrote a SQL statement which it uses to schema your table. Keep that query simple, you might not actually use it in code, and you can always edit that query to update the table schema. In the picture you provided, your default query is actually a stored procedure.
Every time you open the default query it connects to your datasource and allows you to select new columns that weren't in there before. If you want to update your existing columns, delete all the columns out of the table before you attempt to open the query. When you save the query, your updated columns get added back.
Make sure your connection string has permissions to view column information.