Questions tagged [database-table]

In a relational database management system (RDBMS) a table organizes the information in rows and columns. Each table has a defined number of columns, each of which is identified by its name, but the number of rows is variable, consisting of one for each line of data.

In a relational database management system (RDBMS) a table organizes the information in rows and columns. Each table has a defined number of columns, each of which is identified by its name, but the number of rows is variable, consisting of one for each line of data.

More Information:

  1. The wiki entry on database tables is a good source of information.
  2. Microsoft provides an intuitive definition of a table
313 questions
144
votes
11 answers

Facebook database design?

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…
Marin
  • 12,531
  • 17
  • 56
  • 80
139
votes
17 answers

Search All Fields In All Tables For A Specific Value (Oracle)

Is it possible to search every field of every table for a particular value in Oracle? There are hundreds of tables with thousands of rows in some tables so I know this could take a very long time to query. But the only thing I know is that a value…
Chris Conway
  • 16,269
  • 23
  • 96
  • 113
128
votes
9 answers

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

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,…
Peter Craig
  • 7,101
  • 19
  • 59
  • 74
125
votes
9 answers

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

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…
101
votes
15 answers

How to import a CSV file into a MySQL table

How can I import a CSV file into a MySQL table? I would like for the first row of data be used as the column names. I read How do I import CSV file into a MySQL table?, but the only answer was to use a GUI and not a shell?
lcm
  • 1,737
  • 6
  • 17
  • 40
100
votes
7 answers

SQL count rows in a table

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…
Celeste Capece
  • 1,306
  • 2
  • 11
  • 20
92
votes
14 answers

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

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?
lynn
  • 2,868
  • 5
  • 31
  • 34
92
votes
16 answers

Table-level backup

How to take table-level backup (dump) in MS SQL Server 2005/2008?
user82431
  • 1,671
  • 2
  • 14
  • 7
79
votes
3 answers

Count the Number of Tables in a SQL Server Database

I have a SQL Server 2012 database called MyDatabase. How can I find how many tables are in the database? I'm assuming the format of the query would be something like the following, but I don't know what to replace database_tables with: USE…
Tot Zam
  • 8,406
  • 10
  • 51
  • 76
73
votes
10 answers

Add a new table column to specific ordinal position in Microsoft SQL Server

Is it possible to add a column to a table at a specific ordinal position in Microsoft SQL Server? For instance, our tables always have CreatedOn, CreatedBy, LastModifiedOn, LastModifiedBy columns at the "end" of each table definition? I'd like the…
Even Mien
  • 44,393
  • 43
  • 115
  • 119
66
votes
5 answers

Create table variable in MySQL

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?
ANIL MANE
  • 1,395
  • 2
  • 16
  • 30
64
votes
2 answers

How does the search_path influence identifier resolution and the "current schema"

Is it possible to define in which schema new tables get created by default? (Referred by "unqualified table names".) I've seen some details about using the "search path" in Postgres, but I think it only works while retrieving data, not creating. I…
thyandrecardoso
  • 801
  • 1
  • 7
  • 12
53
votes
7 answers

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

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…
Romjin
42
votes
11 answers

MySQL: Select Random Entry, but Weight Towards Certain Entries

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.…
John
  • 421
  • 1
  • 4
  • 3
40
votes
6 answers

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

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…
SocialCensus
  • 1,249
  • 4
  • 15
  • 11
1
2
3
20 21