database-table

SQL count rows in a table

妖精的绣舞 提交于 2019-12-18 14:00:50
问题 I need to send a SQL query to a database that tells me how many rows there are in a table. I could get all the rows in the table with a SELECT and then count them, but I don't like to do it this way. Is there some other way to ask the number of the rows in a table to the SQL server? 回答1: Yes, SELECT COUNT(*) FROM TableName 回答2: select sum([rows]) from sys.partitions where object_id=object_id('tablename') and index_id in (0,1) is very fast but very rarely inaccurate. 回答3: Use This Query :

MySQL Error 1 (HY000) Trouble creating file Errcode 2

自作多情 提交于 2019-12-18 07:10:09
问题 I'm having issues creating a table for my ruby on rails app. It's driving me crazy! The following is returned when I try to create the table: ERROR 1 (HY000): Can't create/write to file '/usr/local/mysql/data/test_development/users.MYI' (Errcode: 2) It's worth mentioning I'm a total newbie, btw. 回答1: This forum post seems to deal with the same problem: Try the following: mkdir /var/lib/mysql/tmp chown mysql:mysql /var/lib/mysql/tmp Add the following line into the [mysqld] section: tmpdir =

Creating a SQL table from a xls (Excel) file

一个人想着一个人 提交于 2019-12-18 06:17:09
问题 I'm trying to convert an Excel document into a table in SQL 2005. I found the link below and am wondering if it looks like a solution. If so, what would the @excel_full_file_name syntax be and where would the path be relative to? http://www.siccolo.com/Articles/SQLScripts/how-to-create-sql-to-convert-Excel_to_table.html 回答1: You can use the BULK INSERT T-SQL command if you just want a pure sql solution. You have to save the file as csv/text first. BULK INSERT YourDestinationTable FROM 'D:

What is the difference between a schema and a table and a database?

五迷三道 提交于 2019-12-17 17:23:25
问题 This is probably a n00blike (or worse) question. But I've always viewed a schema as a table definition in a database. This is wrong or not entirely correct. I don't remember much from my database courses. 回答1: schema : database : table :: floor plan : house : room 回答2: A relation schema is the logical definition of a table - it defines what the name of the table is, and what the name and type of each column is. It's like a plan or a blueprint. A database schema is the collection of relation

SQL DROP TABLE foreign key constraint

血红的双手。 提交于 2019-12-17 14:59:48
问题 If I want to delete all the tables in my database like this, will it take care of the foreign key constraint? If not, how do I take care of that first? GO IF OBJECT_ID('dbo.[Course]','U') IS NOT NULL DROP TABLE dbo.[Course] GO IF OBJECT_ID('dbo.[Student]','U') IS NOT NULL DROP TABLE dbo.[Student] 回答1: No, this will not drop your table if there are indeed foreign keys referencing it. To get all foreign key relationships referencing your table, you could use this SQL (if you're on SQL Server

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

余生颓废 提交于 2019-12-17 10:15:52
问题 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? 回答1: This

Saving changes after table edit in SQL Server Management Studio

限于喜欢 提交于 2019-12-17 05:32:05
问题 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

Facebook database design?

人走茶凉 提交于 2019-12-17 04:08:57
问题 I have always wondered how Facebook designed the friend <-> user relation. I figure the user table is something like this: user_email PK user_id PK password I figure the table with user's data (sex, age etc connected via user email I would assume). How does it connect all the friends to this user? Something like this? user_id friend_id_1 friend_id_2 friend_id_3 friend_id_N Probably not. Because the number of users is unknown and will expand. 回答1: Keep a friend table that holds the UserID and

MySQL: Select Random Entry, but Weight Towards Certain Entries

这一生的挚爱 提交于 2019-12-17 02:11:32
问题 I've got a MySQL table with a bunch of entries in it, and a column called "Multiplier." The default (and most common) value for this column is 0, but it could be any number. What I need to do is select a single entry from that table at random. However, the rows are weighted according to the number in the "Multiplier" column. A value of 0 means that it's not weighted at all. A value of 1 means that it's weighted twice as much, as if the entry were in the table twice. A value of 2 means that it

Oracle: Combine Two Tables with Different Columns

杀马特。学长 韩版系。学妹 提交于 2019-12-12 22:11:08
问题 This is table 1: col_1 col_2 date_1 ----- ----- ------ 1 3 2016 2 4 2015 And this is table 2: col_3 col_4 date_2 ----- ----- ------ 5 8 2014 6 9 2012 I want a result like this: col_1 col_2 col_3 col_4 date_1 date_2 ----- ----- ----- ----- ------ ------ 1 3 NULL NULL 2016 NULL 2 4 NULL NULL 2015 NULL NULL NULL 5 8 NULL 2014 NULL NULL 6 9 NULL 2012 Any solutions? 回答1: Using Union All and Null as a different column: SELECT col_1, col_2, NULL as col_3, NULL as col_4, date_1, NULL as date_2 FROM