Questions tagged [create-table]

The statement that creates a table in SQL (`CREATE TABLE ...`).

The statement that creates a table in SQL (CREATE TABLE ...). Use this tag if your question refers to a problem that might have a relation with an SQL statement that involves a CREATE TABLE statement. Do not use this tag if you have no indication that the CREATE TABLE statement has no relation to the error you are asking about.

1935 questions
567
votes
6 answers

Create a temporary table in a SELECT statement without a separate CREATE TABLE

Is it possible to create a temporary (session only) table from a select statement without using a create table statement and specifying each column type? I know derived tables are capable of this, but those are super-temporary (statement-only) and I…
700 Software
  • 85,281
  • 83
  • 234
  • 341
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
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
128
votes
5 answers

Is it possible to roll back CREATE TABLE and ALTER TABLE statements in major SQL databases?

I am working on a program that issues DDL. I would like to know whether CREATE TABLE and similar DDL can be rolled back in Postgres MySQL SQLite et al Describe how each database handles transactions with DDL.
joeforker
  • 40,459
  • 37
  • 151
  • 246
120
votes
34 answers

MySQL: Error Code: 1118 Row size too large (> 8126). Changing some columns to TEXT or BLOB

I want to create a table of 325 column: CREATE TABLE NAMESCHEMA.NAMETABLE ( ROW_ID TEXT NOT NULL , //this is the primary key 324 column of these types: CHAR(1), DATE, DECIMAL(10,0), DECIMAL(10,7), …
Diego87
  • 1,617
  • 3
  • 17
  • 20
84
votes
13 answers

PostgreSQL Error: Relation already exists

I am trying to create a table that was dropped previously. But when I do the CREATE TABLE A ... I am getting below error: Relation 'A' already exists. I verified doing SELECT * FROM A, but then I got another error: Relation 'A' does not…
nsbm
  • 5,842
  • 6
  • 30
  • 45
82
votes
18 answers

Field 'id' doesn't have a default value?

I am new to this SQL; I have seen similar question with much bigger programs, which I can't understand at the moment. I am making a database for games of cards to use in my homepage. I am using MySQL Workbench on Windows. The error I get is: Error…
Tomas Albertsson
  • 961
  • 1
  • 7
  • 4
80
votes
3 answers

Postgres table column name restrictions?

I did this in psql: CREATE TABLE IF NOT EXISTS apiss (skey TEXT, time INTEGER, user TEXT, ip TEXT); I get ERROR: syntax error at or near "user" LINE 1: ...BLE IF NOT EXISTS apiss (skey TEXT, time INTEGER, user TEXT,... I do: CREATE TABLE IF NOT…
resting
  • 16,287
  • 16
  • 59
  • 90
78
votes
5 answers

create table in postgreSQL

I do not understand what is wrong with this query? Query tool does not want to create a table in PostgreSQL. CREATE TABLE article ( article_id bigint(20) NOT NULL auto_increment, article_name varchar(20) NOT NULL, article_desc text NOT…
user721588
70
votes
6 answers

CREATE TABLE AS with PRIMARY KEY in one statement (PostgreSQL)

Is there a way to set the PRIMARY KEY in a single "CREATE TABLE AS" statement? Example - I would like the following to be written in 1 statement rather than 2: CREATE TABLE "new_table_name" AS SELECT a.uniquekey, a.some_value + b.some_value FROM…
TimY
  • 5,256
  • 5
  • 44
  • 57
65
votes
1 answer

Copy a MySQL table including indexes

I can copy a MySQL table to create a new table: CREATE TABLE newtable SELECT * FROM oldtable This works, but the indexes are not copied to the new table. How can I copy a table including the indexes?
Haim Evgi
  • 123,187
  • 45
  • 217
  • 223
61
votes
2 answers

What does regclass mean in Postgresql

I have the following line in a CREATE TABLE statement: field1_id bigint DEFAULT nextval('table1_field1_id_seq'::regclass) NOT NULL, What does regclass mean in the above? Is it an absolute requirement to add ::regclass? N.B: I had seen the…
saji89
  • 2,093
  • 4
  • 27
  • 49
58
votes
2 answers

Adding named foreign key constraints in a SQL Create statement

I currently have: CREATE TABLE galleries_gallery ( id INT NOT NULL PRIMARY KEY IDENTITY, title NVARCHAR(50) UNIQUE NOT NULL, description VARCHAR(256), templateID INT NOT NULL REFERENCES…
Rumpleteaser
  • 4,142
  • 6
  • 39
  • 52
55
votes
9 answers

Mysql: Setup the format of DATETIME to 'DD-MM-YYYY HH:MM:SS' when creating a table

After googling around, I cannot find a way to create a new table with a DATETIME column with the default format set to 'DD-MM-YYYY HH:MM:SS' I saw a tutorial in which it was done in phpmyadmin so I suspect that I could use mysql via command line and…
Iam Zesh
  • 1,797
  • 2
  • 20
  • 42
50
votes
3 answers

Create hive table using "as select" or "like" and also specify delimiter

Is it possible to do a create table as select using row format delimited fields terminated by '|'; or to do a create table like row format delimited fields terminated by '|'; The Language…
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
1
2 3
99 100