database-table

Which is more efficient: Multiple MySQL tables or one large table?

ⅰ亾dé卋堺 提交于 2019-11-26 04:06:57
问题 I store various user details in my MySQL database. Originally it was set up in various tables meaning data is linked with UserIds and outputting via sometimes complicated calls to display and manipulate the data as required. Setting up a new system, it almost makes sense to combine all of these tables into one big table of related content. Is this going to be a help or hindrance? Speed considerations in calling, updating or searching/manipulating? Here\'s an example of some of my table

T-SQL Pivot? Possibility of creating table columns from row values

断了今生、忘了曾经 提交于 2019-11-26 03:57:54
问题 Is it actually possible to rotate a T-SQL (2005) so that (for the sake of argument) the values of the first column\'s rows become the titles of the output table\'s columns? I realise this is not really what PIVOT is for, but it\'s what I need - the ability to request a table where the columns are not known before-hand because they have been entered as values into a table. Even a hack would be nice, tbh. 回答1: Itzik Ben-Gan's example on how to build dynamic PIVOT, I highly recommend his Inside

Maximum number of records in a MySQL database table

跟風遠走 提交于 2019-11-26 03:48:37
问题 What is the upper limit of records for MySQL database table. I\'m wondering about autoincrement field. What would happen if I add milions of records? How to handle this kind of situations? Thx! 回答1: mysql int types can do quite a few rows: http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html unsigned int largest value is 4,294,967,295 unsigned bigint largest value is 18,446,744,073,709,551,615 回答2: The greatest value of an integer has little to do with the maximum number of rows you can

MySQL > Table doesn't exist. But it does (or it should)

こ雲淡風輕ζ 提交于 2019-11-26 03:32:34
问题 I changed the datadir of a MySQL installation and all the bases moved correctly except for one. I can connect and USE the database. SHOW TABLES also returns me all the tables correctly, and the files of each table exists on the MySQL data directory. However, when I try to SELECT something from the table, I get an error message that the table does not exist. Yet, this does not make sense since I was able to show the same table through SHOW TABLES statement. My guess is that SHOW TABLES lists

Truncating all tables in a Postgres database

回眸只為那壹抹淺笑 提交于 2019-11-26 02:16:28
问题 I regularly need to delete all the data from my PostgreSQL database before a rebuild. How would I do this directly in SQL? At the moment I\'ve managed to come up with a SQL statement that returns all the commands I need to execute: SELECT \'TRUNCATE TABLE \' || tablename || \';\' FROM pg_tables WHERE tableowner=\'MYUSER\'; But I can\'t see a way to execute them programmatically once I have them. 回答1: FrustratedWithFormsDesigner is correct, PL/pgSQL can do this. Here's the script: CREATE OR

Import CSV to mysql table

情到浓时终转凉″ 提交于 2019-11-26 02:05:22
问题 What is the best/fastest way to upload a csv file into a mysql table? I would like for the first row of data be used as the column names. Found this: How to import CSV file to MySQL table But the only answer was to use a GUI and not shell? 回答1: Instead of writing a script to pull in information from a CSV file, you can link MYSQL directly to it and upload the information using the following SQL syntax. To import an Excel file into MySQL, first export it as a CSV file. Remove the CSV headers

Create table variable in MySQL

落花浮王杯 提交于 2019-11-26 01:59:29
I need a table variable to store the particular rows from the table within the MySQL procedure. E.g. declare @tb table (id int,name varchar(200)) Is this possible? If yes how? Preet Sangha They don't exist in MySQL do they? Just use a temp table: CREATE PROCEDURE my_proc () BEGIN CREATE TEMPORARY TABLE TempTable (myid int, myfield varchar(100)); INSERT INTO TempTable SELECT tblid, tblfield FROM Table1; /* Do some more stuff .... */ From MySQL here "You can use the TEMPORARY keyword when creating a table. A TEMPORARY table is visible only to the current connection, and is dropped automatically

Copy tables from one database to another in SQL Server

天涯浪子 提交于 2019-11-26 01:55:46
问题 I have a database called foo and a database called bar. I have a table in foo called tblFoobar that I want to move (data and all) to database bar from database foo. What is the SQL statement to do this? 回答1: On SQL Server? and on the same database server? Use three part naming. INSERT INTO bar..tblFoobar( *fieldlist* ) SELECT *fieldlist* FROM foo..tblFoobar This just moves the data. If you want to move the table definition (and other attributes such as permissions and indexes), you'll have to

Create table variable in MySQL

放肆的年华 提交于 2019-11-26 00:59:57
问题 I need a table variable to store the particular rows from the table within the MySQL procedure. E.g. declare @tb table (id int,name varchar(200)) Is this possible? If yes how? 回答1: They don't exist in MySQL do they? Just use a temp table: CREATE PROCEDURE my_proc () BEGIN CREATE TEMPORARY TABLE TempTable (myid int, myfield varchar(100)); INSERT INTO TempTable SELECT tblid, tblfield FROM Table1; /* Do some more stuff .... */ From MySQL here "You can use the TEMPORARY keyword when creating a

Auto increment table column

痞子三分冷 提交于 2019-11-25 23:59:51
问题 Using Postgres, I\'m trying to use AUTO_INCREMENT to number my primary key automatically in SQL. However, it gives me an error. CREATE TABLE Staff ( ID INTEGER NOT NULL AUTO_INCREMENT, Name VARCHAR(40) NOT NULL, PRIMARY KEY (ID) ); The error: ********** Error ********** ERROR: syntax error at or near \"AUTO_INCREMENT\" SQL state: 42601 Character: 63 Any idea why? 回答1: Postgres 10 or later serial columns (see below) remain unchanged. But consider an IDENTITY column. Postgres 10 implements this