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
49
votes
2 answers

How do I create a table based on another table

I want to create a table based on the definition of another table. I'm coming from oracle and I'd normally do this: CREATE TABLE schema.newtable AS SELECT * FROM schema.oldtable; I can't seem to be able to do this in SQL Server 2008.
oliverdejohnson
  • 1,512
  • 2
  • 14
  • 22
48
votes
6 answers

How to create a table in a particular database?

The create database statement is: CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, column_name3 data_type, .... ) But I'm wondering how can I create a table in a specific database?
user295515
  • 877
  • 3
  • 8
  • 12
48
votes
5 answers

SQLite Foreign Key

I'm following the instructions from the SQLite documentation at http://www.sqlite.org/foreignkeys.html however my attempt to add a foreign key is failing. Here are my create statements: CREATE TABLE checklist ( _id INTEGER PRIMARY KEY…
Geeks On Hugs
  • 1,591
  • 2
  • 18
  • 31
43
votes
1 answer

postgres: create table in database from the command line

I am trying to create a table in postgres, but it ends up in the wrong database. Here is what I do: in my sql script initially I create a user and a database, and then a table. Code will explain more: drop database if exists sinfonifry; drop role if…
Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167
40
votes
1 answer

Creating new table with SELECT INTO in SQL

Possible Duplicate: SELECT INTO using Oracle I have came across SQL SELECT INTO statement for creating new table and also dumping old table records into new table in single SQL statement as SELECT * INTO NEW_TABLE FROM OLD_TABLE; But when i am…
Aspirant
  • 2,238
  • 9
  • 31
  • 43
39
votes
2 answers

Cannot create a new table after "DROP SCHEMA public"

Since I wanted to drop some tables and somebody suggested the below and I did it: postgres=# drop schema public cascade; DROP SCHEMA postgres=# create schema public; CREATE SCHEMA Then I got problem when creating a new database, such as: postgres=#…
user1342336
  • 967
  • 2
  • 16
  • 28
36
votes
6 answers

PostgreSQL: Create table if not exists AS

I'm using PostgreSQL and am an SQL beginner. I'm trying to create a table from a query, and if I run: CREATE TABLE table_name AS (....query...) it works just fine. But then if I add 'if not exists' and run: CREATE TABLE IF NOT EXISTS table_name…
user3591836
  • 953
  • 2
  • 16
  • 29
34
votes
3 answers

Mysql set default value to a json type column

I heard that mysql version prior to 8.0.13 accept default value for json type column, so I using the cmd: ALTER TABLE templates CHANGE COLUMN values JSON NOT NULL DEFAULT '{}' ; but receive error: Error Code: 1101. BLOB, TEXT, GEOMETRY or JSON…
Dave kam
  • 373
  • 1
  • 3
  • 5
33
votes
1 answer

Do I need to create separate index for primary key of relational database table

If I create table with primary key is index automatically created for the table or does that need doing separately. i.e if this is the table ddl CREATE TABLE release(guid varchar(36) NOT NULL PRIMARY KEY, name varchar(255),xmldata CLOB(512 K)) do…
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
30
votes
2 answers

What is the difference between UNIQUE, UNIQUE KEY and CONSTRAINT 'name' UNIQUE?

I have a basic users table I want to create in MySQL. I do not want duplicate emails or duplicate usernames appearing in the database. What is the best way of preventing this upon table creation? And what is the difference between the…
30
votes
5 answers

Primary key in cassandra is unique?

It could be kind of lame but in cassandra has the primary key to be unique? For example in the following table: CREATE TABLE users ( name text, surname text, age int, adress text, PRIMARY KEY(name, surname) ); So if is it possible in my…
DarKAngeL
  • 361
  • 1
  • 3
  • 8
30
votes
4 answers

Alter table if exists or create if doesn't

I need to run an installer which can also be an updater. The installer needs to be able to end up having a certain scheme/structure of the mysql database, regardless if some of the tables existed, missed a few columns, or need not to be changed…
Alon_T
  • 1,430
  • 4
  • 26
  • 47
29
votes
6 answers

CREATE TABLE permission denied in database 'tempdb'

First time I installed SQL Server Management Studio Express and Visual Studio 2005 on my system. Now I am trying to create table by using below script. But if once I execute I am facing error like CREATE TABLE permission denied in database…
Raju
  • 293
  • 1
  • 3
  • 4
28
votes
1 answer

Column, parameter, or variable #10: Cannot find data type

I'm trying to create table from template code. This template code is working: CREATE TABLE [dbo].[Table1] ( [Field1] [int] NULL, [Field2] [float] NULL ) ON [PRIMARY] But if I put varchar(10): CREATE TABLE [dbo].[Table1] ( …
hoggar
  • 3,699
  • 5
  • 31
  • 41
26
votes
4 answers

SQL Server - Can you add field descriptions in CREATE TABLE?

I can see plenty of posts about where the field description extended property lives and how I can get it, but nothing about adding these at the CREATE TABLE stage. I'm dynamically creating tables so dynamically adding field descriptions would be a…
Mike
  • 261
  • 1
  • 3
  • 5