Exporting MS SQL Schema and Data - asp.net

I'm used to MySQL and PHPMyAdmin - I had to switch over to MSSQL for an ASP.net project, and I'm having tons of trouble. I'm using the express version of SQL 2008, with SQL Server Management Studio. The following are 2 questions I've been struggling with for a while:
1) How do I export the DB schema for the database? The table structure, etc.?
2) How do I export all the data in the database?
Ideally I'd like to have a .sql file that can be run wherever I need the schema or data duplicated, for example a co-worker's computer for a shared project, or online when the project is being hosted.
Thanks!

1) How do I export the DB schema for the database? The table structure, etc.?
INFORMATION_SCHEMA is your friend
SELECT * FROM INFORMATION_SCHEMA.TABLES
http://www.mssqltips.com/tutorial.asp?tutorial=179
http://weblogs.asp.net/jgalloway/archive/2006/07/07/455797.aspx
http://preetul.wordpress.com/2009/06/09/sql-server-information_schema/
Otherwise, if you want something pretty looking, download the 14 day trial of SQL Doc (part of SQL Toolbelt) here:
http://www.red-gate.com/products/SQL_Professional_Toolbelt/index.htm
"2) How do I export all the data in the database?"
In what form? .bak files are typically the most useful. http://www.sqlteam.com/article/backup-and-restore-in-sql-server-full-backups
Or were you looking to move the data into MYSQL or Excel or some other program? If you want to move data to MYSQL check here: http://www.google.com/search?q=mssql+to+mysql

Related

a file-base FoxPro Database in asp.net issues

I have a collection of data stored in a FoxPro database in my local system . I want to use this data in my website . now I don't know what is the best way to use it .
1- to place the database itself in app_data and use VFP Oledb provider to extract data from ?
2- Or to use it as a linked server with my current sql server ?
3- or create a page that uploads VFP database then export it's records to a sql server database with the same schema ?
I can't answer these questions because :
I don't know how secure and scalable is a database placed in app_data /
is FoxPro database a good choice as a website backend data store /
exporting data from VPF to Sql database through code is not error proof ( I'm not sure if I lose records and FKs )
how often the data change? Do you need it real time? If yes, give it a try with linked servers:
http://support.microsoft.com/kb/199131
If you can have a X hours\minutes delay (that will depend on the size of your data), how about building SSIS packages to run on a regular basis to get the data from FoxPro and insert into a SQl Server database?
Visual FoxPro also has an upsizing wizard that will do the heavy lifting of converting your Visual Foxpro database to SQL Server including the table structures and data.

How can I convert my Access database (.accdb) to SQLite?

How can I convert my Access database (.accdb) to an SQLite database(.sqlite)?
May be you can use several step algoritm:
1. Export (convert) Access table or query to Excel file
2. Save Excel file as CSV file.
3. Use any SQLLite manager (for example, phpLiteAdmin) to import data from CSV file to exist SQLLite table.
Except Android and IOS, that use SQLLite, there are still webhostings, that use no more database engine, except for SQLLite.
1) If you want to convert a structure of db you shoud use any DB-modeling tools:
create new model from existing Access Database
generate sql scripte for creating SQLite database
use this script in SQL helper
2) If you want to import data from Access Database to your android app. I think you can do case #1, migrate all data from Access Database to temporary SQLite database, save it to asset folder and rewrite from asset to internal SQLite database during first app. start

Import And Export data

I want to export bulk of records from a table in Sqlserver database to a file and after that i want to import that file to another table in another database .
my project is Asp.net
my Database is Sqlserver 2008
how do i can do this and what kind of file is faster to use?(XML,TXT,...)
thanks so much
You can use bcp utility that comes along with sqlserver. More details at http://msdn.microsoft.com/en-us/library/aa337544.aspx
in sql server management
Right click on DB then select task->generate script
follow wizard....

Importing Excel Table into a MS SQL Table

I have software for STOCK and SALES that can give me an Excel price list, I wanna write a small web app that will enable users to check prices, I don't have any access to that software's database, so I wanna import that Excel data (one worksheet, 5 columns, almost 10000 rows) into an MS SQL database table, keep in mind that the price list will change few time a month so I need to re-import that price list once its been updated.
Any suggestions? or maybe I should skip using an MS SQL database and directly use the Excel sheet? if so, then how?!
I'd go directly to SQL Server. Let it do the heavy lifting. If one of your users wants to export data to Excel, by all means provide such a feature. But multi-user changes to the data should be done in SQL Server via the web. Excel should be a local, read-only, personal copy to download and nothing else.
SQL Server can easily import an Excel spreadsheet or .csv file, especially if we're talking about a single table with five columns. I'd still have SQL Server do all the work on the web side.
If you save the Excel file as a CSV, it doesn't take much of a program to convert that into SQL statements.
You can use bulk upload to upload data from excel to sql server. Please look at the link below
http://www.gyansangrah.com/ArticleContent.aspx?ID=bulk_upload_in_asp_net
Please let me know in case of any issues.

Updating SQL Server database with SQL scripts

I have a number of manually written scripts (.sql) for tables, views and stored procedures that are used from an ASP.NET application. These scripts drop the object and recreates them. I need a way to update the database when the scripts change without deleting the object. For example, when a column is added to an existing table that has rows in it, I would need to update this table with this extra column without losing the rows.
I need a way to "update" the database on a single click (I can hook up the changes using a batch file). Does Visual Studio support this kind of functionality?
If you get Visual Studio Team System - Database Edition 2008 - which is now bundled with "Developer Edition" for free - it handles that. Visual Studio database projects without that edition really just store the static SQL that you want to track. The Database Edition is capable of determining the 'deltas' between your SQL and what's in a target database, generating that script, and executing against your database. You do get the option of reviewing that generated SQL, but by default it is very safe [it won't run if it thinks that there will be any data lost].
Yes - it's called Database Projects.
You can define a Visual Studio Database Projects, have create and change SQL scripts inside it, and then execute those against a database connection of your choice when you need to.
See this blog post here for a great explanation, or read the whole series that the 4 guys from Rolla wrote.

Resources