314 questions
2642 votes
28 answers
3.4m views
How to show tables in PostgreSQL?
What's the equivalent to show tables (from MySQL) in PostgreSQL?
1132 votes
22 answers
2.4m views
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?
1060 votes
15 answers
730k views
How do I specify unique constraint for multiple columns in MySQL?
I have a table: table votes ( id, user, email, address, primary key(id), ); How can I make the columns user, email, address unique - i.e., ensure that there isn't any pair of rows ...
648 votes
26 answers
904k views
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 ...
621 votes
21 answers
584k views
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 PostgreSQL. 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 ...
402 votes
10 answers
418k views
Dump only the data with mysqldump without any table information
I am looking for the syntax for dumping all data in my mysql database. I don't want any table information.
380 votes
2 answers
322k views
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.
355 votes
8 answers
969k views
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 ...
336 votes
6 answers
523k views
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?
322 votes
7 answers
293k views
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 ...
308 votes
17 answers
730k views
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?
308 votes
34 answers
688k views
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 ...
249 votes
18 answers
352k views
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 ...
236 votes
14 answers
317k views
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 ...
234 votes
15 answers
293k views
How to dump the data of some SQLite3 tables?
How do I dump the data, and only the data, not the schema, of some SQLite3 tables of a database (not all the tables)? The dump should be in SQL format, as it should be easily re-entered into the ...