Please help, I have large database in DBF where have 34 column and more than 50k record.
In this case, I need 10 column only from 34 column. Logically, if I delete not necessary column will reduce data load.
So I will copy structure and data from source file with specific column, but I do not know how to do it in visual foxpro.
Will you help me for this case ?
Before and after, thanks for your attention to read my problem.
Regards,
Pathic
Use the following syntax:
SELECT col1,col2,col3,col4,col5,col6,col7,col8,col9,col10 FROM table1 INTO TABLE table2
If you only want to REMOVE the column PERMANENTLY, first, for grins, make a backup copy of the file. Then, make sure you are out of any program using that table and start VFP. In the command window, enter
USE C:\SomePath\YourTable EXCLUSIVE {enter}
*/ Now, get the one column you want copied out... you can just add as many
*/ Columns, such as any primary key reference you may also want to include to.
COPY TheOneColumnYouWant to C:\SomePath\NewTableForThisColumnOnly {enter}
*/ Now, to remove the column from the original table, now that is has been moved
*/ to the "other" table.
MODIFY STRUCTURE {enter}
This brings up a modify table structure where you can alter / delete ANY column. Scroll down the list to the column you want to delete, and at the bottom, click the DELETE button, then click the OK button to confirm structure changes. It will then come back with a confirmation prompt to "Make structure changes permanent?" and select Yes. Column now gone.
An alternative to deleting columns in VFP, you can use Alter Table via...
ALTER table C:\SomePath\YourTable DROP COLUMN TheOneColumnYouWant
Related
I have thousands of rows in my Microsoft Access DB and I would like to update all values in the column "Documento_Digitalizado". Values in this column are raw text that must be updated to be an hyperlink.
(The hyperlink direction has to be the text value of the cell)
This is my Access DB
This is the way to update them one by one.
First save a copy of your table just in case!
Create a query to up-date your original table Documento_Digitalizado column to show FULL file path if it does not already show it.
Then open your original table in design mode.
Change field type of Documento_Digitalizado from text to hyperlink
save, close.
To bulk edit hyperlink fields change date type from hyperlink to text, create and run query to amend file location, change field data type back to hyperlink
I had to change drive letter in hyperlink. Changed table column to long text from hyperlink and saved. Exported to Excel. Dropped existing rows from table. Bulk changed the drive letter in Excel. Loaded to now empty table. Changed table column to hyperlink.
300 rows of reference document links, 3 minutes to fix.
I've got table A and table B in a database. I'm trying to move the column in table A to table B without losing any data. Not sure if its best to move the column somehow or make a whole new column in table B then copy the data over?
The problem is that the database is already in production and I don't want the clients to lose the data that is currently stored in column X in table A. I thought of making a migration to create the same column X in table B, and then somehow copying the data there. I am not sure how to do that, and I couldn't find a similar problem here.
if you have phpmyadmin you can do this pretty easily. this command should work:
INSERT INTO `tabletwo.columnb` (SELECT 'columna' FROM tableone)
Always back up the dbs, load local and try this, never live lol. I'm sure your aware. :)
Note: columna and columnb are placeholder for your actual column names
I think you can create the migration table to create de column on table B.
After you can use tinker ("php artisan tinker" on the terminal) to move the desired data on the table A to the B.
I was referencing this question How to export all data from table to an insertable sql format?
while looking for a way to create an insert statement for a single row from a table without having to manually write it since the table has many columns. In my case I simply followed the steps listed then performed a ctrl-f search in the resulting script for the record I wanted then copied and pasted that single line to another query window but this would be terrible if I had hundreds of millions of rows. Is there a way to get the same functionality but tell the script generator I only want rows where id = value? Is there a better way to do this using only the out of the box Microsoft tools?
There is no way to do this, but you can do it by using a temp table
Create a new table by inset into and select those records which you want to insert.
Create the script and change the table name by using find and replace.
finally drop that temporary table.
I've lost my data in Access base, and I've manage to bring them back but when I copy the values in the table with the AutoNumber Column it increments the numbers.
Is there Any way to change it to int and then bring it back to AutoNumber?
Here is how I managed to do this in Access 2010:
Make a backup of your database. (Just to be safe.)
Right-click on the table in the tables list, and select Export->Excel. Accept all defaults.
Open the table in Excel and make the desired change to the autonumber field.
Open the table and delete all rows
Right-click on table in the tables list, and select Import->Excel
In the options, choose "Append to table" and select the table. Accept defaults for all other options
This might not be a viable solution for a large table. I don't think Excel can handle more than around 65K rows.
Don't copy the data with the user interface, but append it with a query. Because an Autonumber field is just a long integer with a special default value, you can append to it values that already exist. That doesn't work in the UI, but only in SQL.
An Autonumber field has a few other properties that are different from a normal Long Integer field, but in terms of appending data, those are not relevant. One of those properties is that it is not editable once it's populated, and another is that you can have only one in each table.
I've manage to insert the AutoNumber fields by code from c#.
I take all the data I need and just inserted in an empty table.
How are you bringing the data back? It should be possible to append the data from your table and to keep the existing numbers.
It is necessary however, that you paste from an integer field to the autonumber field. You cannot change a field to autonumber from integer once there is data in the field, but you can change to integer from autonumber.
Make backup of your data table. Delete all data form original table and then do compact & repair your database. By doing this, auto number field will be reset at 1. You may now append your data from backup table.
SQL code like
insert into <tablename>
(<column 1>, <column2>, ...)
values
( <value 1>, <value 2>, ...);
will do the trick if you include the autonumber column in your query. It's pretty tedious, but works. You can switch to SQL mode for any old query to enter this text (usually after preparing it in a text editor), or as #Dominic P points out, you can bring up a VBA immediate window and run DoCmd.RunSQL "INSERT INTO ..." which will give you a better editor experience within Access.
Why does SQL 2008 all of a sudden want to drop my tables when I go to change the column type from say int to real? This never happened in SQL 2005 to my knowledge. Any insight would be helpful please.
I can't believe the top answer has been sitting here for so long - it is very dangerous advice!
There are few operations that you can do inplace without dropping your table:
Expand a varchar column https://dba.stackexchange.com/questions/5211/changing-column-width
Make a column nullable (but not vice-versa)
Renaming columns using sp_rename
If you find yourself in the situation where altering a column is not possible without dropping the table, you can usually use a SELECT INTO query to project your data into a new table, then drop the old table (temporarily disabling constraints) and then renaming the projected table. You will need to take your database offline for maintenance in this case though.
In SQL Server 2008, go to Tools >> Options. In the little window, click "Designer". Uncheck "Prevent saving changes that require ..."
=====
Edited on Sept 4th, 2015.
I have added this answer here a long, long time ago describing the way I would solve the situation described on the question above. Since then, users on the threads below have exposed several concerns on doing things the way I recommended at the time. Basically, the solution I described could be problematic on some scenarios. I then suggest you to keep on reading to check other users' comments and pick the best solution for you.
Here is what I use:
-- Add new column
ALTER TABLE MyTable
ADD Description2 VARCHAR(MAX)
GO
-- Copy data to new column (probably with modifications)
Update MyTable
SET Description2 = Description
GO
-- Drop old column
ALTER TABLE MyTable
DROP COLUMN Description
GO
-- Rename new column to the original column's name.
sp_RENAME 'MyTable.Description2' , 'Description', 'COLUMN'
GO
Copy the data into a new column.
Drop the old column.
Rename the new column to the old column's name.
I have the same issue. Athough my account has sa rights if I try using another sa account it works. It seems that somehow my account does not have the ability to alter. still investigating, but it is a permission issue.
update:
I cannot expain it. but this is what I did. there two domain groups my account belonged to. One was a new AD domain group and the other was an NT legay domain group. Once I removed the legacy domain group I was able to alter the table successfully. Mind you both groups had "sa" priviliges.
The behavior was that the alter commands would result in success, but nothing changed on the table. Then when I manually tried to change the fields through the designer it complained that I was not allowed to make change if it required to drop and recreate the table. I found the setting in tools and I was able to turn that off. But this table is huge and not a good idea to do this. I woud advise others against it.
so it was a permission issue. I can't explain how, but I hope it helps someone else
Another way to this without totally dropping the table is
Take a backup of the column values.
Make the column nullable if it does not already allow nulls. Set the column values to be null by
doing
update tablename set columnname = null
Delete the column
Insert a new column with the same name as the deleted column and the type which you want
Insert the saved data into this column