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
1063
votes
20 answers

How do I get list of all tables in a database using TSQL?

What is the best way to get the names of all of the tables in a specific database on SQL Server?
Ray
  • 187,153
  • 97
  • 222
  • 204
1037
votes
14 answers

How do I specify unique constraint for multiple columns in MySQL?

I have a table: table votes ( id, user, email, address, primary key(id), ); Now I want to make the columns user, email, address unique (together). How do I do this in MySql? Of course the example is just... an example. So please…
Niyaz
  • 53,943
  • 55
  • 151
  • 182
569
votes
25 answers

How to get a list of column names on Sqlite3 database?

I want to migrate my iPhone app to a new database version. Since I don't have some version saved, I need to check if certain column names exist. This Stackoverflow entry suggests doing the select SELECT sql FROM sqlite_master WHERE tbl_name =…
luebken
  • 6,221
  • 5
  • 22
  • 18
569
votes
21 answers

How do you find the row count for all your tables in Postgres

I'm looking for a way to find the row count for all my tables in Postgres. I know I can do this one table at a time with: SELECT count(*) FROM table_name; but I'd like to see the row count for all the tables and then order by that to get an idea…
mmrobins
  • 12,809
  • 7
  • 41
  • 42
340
votes
2 answers

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

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.
user461112
  • 3,811
  • 3
  • 20
  • 25
338
votes
8 answers

Copy tables from one database to another in SQL Server

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?
RyanKeeter
  • 5,939
  • 7
  • 32
  • 40
308
votes
7 answers

Saving changes after table edit in SQL Server Management Studio

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…
rem
  • 16,745
  • 37
  • 112
  • 180
303
votes
17 answers

How can I create a copy of an Oracle table without copying the data?

I know the statement: create table xyz_new as select * from xyz; Which copies the structure and the data, but what if I just want the structure?
Andrew
  • 12,991
  • 15
  • 55
  • 85
294
votes
34 answers

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

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…
johnsmith
  • 3,009
  • 2
  • 15
  • 8
294
votes
6 answers

PostgreSQL create table if not exists

In a MySQL script you can write: CREATE TABLE IF NOT EXISTS foo ...; ... other stuff ... and then you can run the script many times without re-creating the table. How do you do this in PostgreSQL?
peter2108
  • 5,580
  • 6
  • 24
  • 18
219
votes
18 answers

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

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.
anbanm
  • 13,425
  • 5
  • 22
  • 17
216
votes
14 answers

Truncating all tables in a Postgres database

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…
Sig
  • 4,988
  • 3
  • 28
  • 29
209
votes
8 answers

Maximum number of records in a MySQL database table

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!
xpepermint
  • 35,055
  • 30
  • 109
  • 163
193
votes
17 answers

SQL DROP TABLE foreign key constraint

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…
user188229
170
votes
10 answers

Mysql: Select rows from a table that are not in another

How to select all rows in one table that do not appear on another? Table1: +-----------+----------+------------+ | FirstName | LastName | BirthDate | +-----------+----------+------------+ | Tia | Carrera | 1975-09-18 | | Nikki | Taylor …
user1006989
1
2 3
20 21