Generating TCP-H database for SqlServer 2008 - sql

Is there any way to populate TCP-H database for Microsoft SQL Server 2008.
TPC-H provides a DBGEN tool that can create huge tables according to a schema. By default, it generates text files (one per table) with tuples represented in lines and '|' separating the columns in a tuple and new line for the tuple end.
I need that huge table to be imported in SQL Server 2008.

This is the method.

Related

how many FileTables we can create in SQL Server 2012?

i am using SQL Server 2012 and would like to implement FileTables feature in application. how many FileTable we can create in one Database in SQL Server 2012?
The number of tables allowed in a single database is limited to the total number of object, which can't exceed 2,147,483,647. I've never run across any article that diferentiates between regular tables and file tables.
http://msdn.microsoft.com/en-us/library/ms143432(v=sql.110).aspx

Generate Code for MS SQL Database Schema

I don't know if I am using the correct terminology here.
I want to recreate the tables of a local database on my computer on another one. I do not care about duplicating the data stored, but just the tables, their relationships, constraints etc.
I have been using Microsoft SQL 2012. Is there a way to generate the SQL code that defines my tables. (What I would have typed to set up my tables had I not done it graphically)

How do you transfer all tables between databases using SQL Management Studio?

When I right click on the database I want to export data from, I only get to select a single table or view, rather than being able to export all of the data. Is there a way to export all of the data?
If this is not possible, could you advise on how I could do the following:
I have two databases, with the same table names, but one has more data than the other
They both have different database names (Table names are identical)
They are both on different servers
I need to get all of the additional data from the larger database, into the smaller database.
Both are MS SQL databases
Being that both are MS SQL Servers, on different hosts... why bother with CSV when you can setup a Linked Server instance so you can access one instance from the other via a SQL statement?
Make sure you have a valid user on the instance you want to retrieve data from - it must have access to the table(s)
Create the Linked Server instance
Reference the name in queries using four name syntax:
INSERT INTO db1.dbo.SmallerTable
SELECT *
FROM linked_server.db.dbo.LargerTable lt
WHERE NOT EXISTS(SELECT NULL
FROM db1.dbo.SmallerTable st
WHERE st.col = lt.col)
Replace WHERE st.col = lt.col with whatever criteria you consider to be duplicate values between the two tables.
There is also a very good tool by Redgate software that syncs data between two databases.
I've also used SQL scripter before to generate a SQL file with insert statements that you can run on the other database to insert the data.
If you right-click on the database, under the Tasks menu, you can use the Generate Scripts option to produce SQL scripts for all the tables and data. See this blog post for details. If you want to sync the second database with the first, then you're better off using something like Redgate as suggested in mpenrow's answer.

How do I create tables in VS 2008?

I am running VS 2008 Standard and SQL Server Express. I created the tables in the Database Designer (creating and xsd), and created the database. How do I get the tables from the Database Designer into the database? Also, is there some documentation available?
Thanks!
My original flow would've been to:
use Server Explorer in Visual Studio to create tables, views and stored procs.
Create the .xsd model 'from database' instead of by hand.
The xsd really is the model for how the data is shaped in the application, rather than in storage at the database.
Unsure if there is a way to explicitly export/create SQL scripts from your .xsd designer. If it was enough of a time-saver, you could:
create a new TSQL query, copy paste the XSD into a varchar(max) variable.
use OPENXML to get a set of the names of the tables & their columns.
create SQL statements for CREATE TABLE

How to do a search and replace of a part of a string in all columns in all tables in an sql database

Is it possible to search and replace all occurrences of a string in all columns in all tables of a database? I use Microsoft SQL Server.
Not easily, though I can thing of two ways to do it:
Write a series of stored procedures that identify all varchar and text columns of all tables, and generate individual update statements for each column of each table of the form "UPDATE foo SET BAR = REPLACE(BAR,'foobar','quux')". This will probably involve a lot of queries against the system tables, with a lot of experimentation -- Microsoft doesn't go out of its way to document this stuff.
Export the entire database to a single text file, do a search/replace on that, and then re-import the entire database. Given that you're using MS SQL Server, this is actually the easier approach. Microsoft created the Microsoft SQL Server Database Publishing Wizard for other reasons, but it makes a fine tool for exporting all of the tables of a SQL Server database as a text file containing pure SQL DDL and DML. Run the tool to export all of the tables for a database, edit the resulting file as you need, and then feed the file back to sqlcmd to recreate the database.
Given a choice, I'd use the second method, as long as the DPW works with your version of SQL Server. The last time I used the tool, it met my needs (MS SQL Server 2000 / 2005) but it had some quirks when working with database Roles.
In MySQL, you can do it very easily like this:
update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
I have personally tested this successfully on a production server.
Example:
update users set vct_filesneeded = replace(vct_filesneeded,'.avi','.ai');
Ref: http://www.mediacollege.com/computer/database/mysql/find-replace.html
A good starting point for writing such a query is the "Search all columns in all the tables in a database for a specific value" stored procedure. The full code is at the link (not trivial, but copy/paste it and use it, it just works).
From there on it's relatively trivial to amend the code to do a replace of the found values.