database-table

SQL Server 2005 - Export table programmatically (run a .sql file to rebuild it)

耗尽温柔 提交于 2019-11-27 10:51:17
I have a database with a table Customers that have some data I have another database in the office that everything is the same, but my table Customers is empty How can I create a sql file in SQL Server 2005 (T-SQL) that takes everything on the table Customers from the first database, creates a, let's say, buildcustomers.sql, I zip that file, copy it across the network, execute it in my SQL Server and voila! my table Customers is full How can I do the same for a whole database? The Matt This functionality is already built in to Sql Server Management Studio 2008. Just download the trial and only

Table-level backup

梦想的初衷 提交于 2019-11-27 10:31:11
How to take table-level backup (dump) in MS SQL Server 2005/2008? John Sansom You cannot use the BACKUP DATABASE command to backup a single table, unless of course the table in question is allocated to it's own FILEGROUP . What you can do, as you have suggested is Export the table data to a CSV file. Now in order to get the definition of your table you can 'Script out' the CREATE TABLE script. You can do this within SQL Server Management Studio, by: right clicking Database > Tasks > Generate Script You can then select the table you wish to script out and also choose to include any associated

MySQL - Select from a list of numbers those without a counterpart in the id field of a table

雨燕双飞 提交于 2019-11-27 08:49:09
I have a list of numbers, say {2,4,5,6,7} I have a table, foos, with foos.ID, including say, {1,2,3,4,8,9} Id like to take my list of numbers, and find those without a counterpart in the ID field of my table. One way to achieve this would be to create a table bars, loaded with {2,4,5,6,7} in the ID field. Then, I would do SELECT bars.* FROM bars LEFT JOIN foos ON bars.ID = foos.ID WHERE foos.ID IS NULL However, I'd like to accomplish this sans temp table. Anyone have any input on how it might happen? This is a problem that is pretty common: generating a relation on the fly without creating a

Copy a table from one database to another in Postgres

巧了我就是萌 提交于 2019-11-27 04:55:47
问题 I am trying to copy an entire table from one database to another in Postgres. Any suggestions? 回答1: Extract the table and pipe it directly to the target database: pg_dump -t table_to_copy source_db | psql target_db 回答2: You can also use the backup functionality in pgAdmin II. Just follow these steps: In pgAdmin, right click the table you want to move, select "Backup" Pick the directory for the output file and set Format to "plain" Click the "Dump Options #1" tab, check "Only data" or "only

SQL Server: drop table cascade equivalent?

狂风中的少年 提交于 2019-11-27 04:37:13
In oracle, to drop all tables and constraints you would type something like DROP TABLE myTable CASCADE CONSTRAINTS PURGE; and this would completely delete the tables and their dependencies. What's the SQL server equivalent?? I don't believe SQL has a similarly elegant solution. You have to drop any related constraints first before you can drop the table. Fortunately, this is all stored in the information schema and you can access that to get your whack list. This blog post should be able to get you what you need: http://weblogs.asp.net/jgalloway/archive/2006/04/12/442616.aspx -- t-sql

Create table in SQLite only if it doesn't exist already

拜拜、爱过 提交于 2019-11-27 02:58:44
I want to create a table in a SQLite database only if doesn't exist already. Is there any way to do this? I don't want to drop the table if it exists, only create it if it doesn't. From http://www.sqlite.org/lang_createtable.html : CREATE TABLE IF NOT EXISTS some_table (id INTEGER PRIMARY KEY AUTOINCREMENT, ...); 来源: https://stackoverflow.com/questions/4098008/create-table-in-sqlite-only-if-it-doesnt-exist-already

Is there any reason to worry about the column order in a table?

痞子三分冷 提交于 2019-11-27 02:35:28
I know you can ALTER the column order in MySQL with FIRST and AFTER, but why would you want to bother? Since good queries explicitly name columns when inserting data, is there really any reason to care what order your columns are in in the table? Column order had a big performance impact on some of the databases I've tuned, spanning Sql Server, Oracle, and MySQL. This post has good rules of thumb : Primary key columns first Foreign key columns next. Frequently searched columns next Frequently updated columns later Nullable columns last. Least used nullable columns after more frequently used

How to reduce size of SQL Server table that grew from a datatype change

前提是你 提交于 2019-11-27 01:20:33
问题 I have a table on SQL Server 2005 that was about 4gb in size. (about 17 million records) I changed one of the fields from datatype char(30) to char(60) (there are in total 25 fields most of which are char(10) so the amount of char space adds up to about 300) This caused the table to double in size (over 9gb) I then changed the char(60) to varchar(60) and then ran a function to cut extra whitespace out of the data (so as to reduce the average length of the data in the field to about 15) This

Why use multiple columns as primary keys (composite primary key)

孤人 提交于 2019-11-26 23:49:26
This example is taken from w3schools . CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName) ) My understanding is that both columns together ( P_Id and LastName ) represent a primary key for the table Persons . Is this correct? Why would someone want to use multiple columns as primary keys instead of a single column? How many columns can be used together as a primary key in a given table? MJB Your understanding is correct. You would do this in many cases. One

Saving changes after table edit in SQL Server Management Studio

我的梦境 提交于 2019-11-26 21:20:45
If I want to save any changes in a table, previously saved in SQL Server Management Studio (no data in table present) I get an error message: Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created. What can prevent the table to be easily edited? Or, is it the usual way for SQL Server Management Studio to require re-creating table for editing? What is it - this "option Prevent saving