create-table

Copy a MySQL table including indexes

混江龙づ霸主 提交于 2019-11-27 12:53:54
问题 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? 回答1: CREATE TABLE newtable LIKE oldtable; INSERT INTO newtable SELECT * FROM oldtable; 来源: https://stackoverflow.com/questions/2415855/copy-a-mysql-table-including-indexes

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

假装没事ソ 提交于 2019-11-27 12:35:08
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 Code: 1364. Field 'id' doesn't have a default value CREATE TABLE card_games ( nafnleiks varchar(50), leiklysing varchar(3000), prentadi varchar(1500), notkunarheimildir varchar(1000), upplysingar varchar(1000), ymislegt varchar(500), id int(11) PK ); insert into card_games (nafnleiks, leiklysing, prentadi, notkunarheimildir, upplysingar, ymislegt)

Create Table in Hive with one file

不羁岁月 提交于 2019-11-27 09:48:41
I'm creating a new table in Hive using: CREATE TABLE new_table AS select * from old_table; My problem is that after the table is created, It generates multiple files for each partition - while I want only one file for each partition. How can I define it in the table? Thank you! There are many possible solutions: 1) Add distribute by partition key at the end of your query. Maybe there are many partitions per reducer and each reducer creates files for each partition. This may reduce the number of files and memory consumption as well. hive.exec.reducers.bytes.per.reducer setting will define how

How to create n number of external tables with a single hdfs path using Hive

二次信任 提交于 2019-11-27 09:37:11
Is it possible to create n number of external tables are pointing to a single hdfs path using Hive. If yes what are the advantages and its limitations. It is possible to create many tables (both managed and external at the same time) on top of the same location in HDFS. Creating tables with exactly the same schema on top of the same data is not useful at all, but you can create different tables with different number of columns for example or with differently parsed columns using RegexSerDe for example, so you can have different schemas in these tables. And you can have different permissions on

Try to create a table from Select - SqL Server 2008 throws error

吃可爱长大的小学妹 提交于 2019-11-27 04:48:52
问题 Hi I am trying to create a table using inner select statement... for example: CREATE TABLE JmxMonSer AS (SELECT * FROM services WHERE monitoring_enabled = 1); But keep getting error: Incorrect Syntax near keyword 'AS', Severity 15 please advice 回答1: How about: SELECT * into JmxMonSer FROM services WHERE monitoring_enabled=1 If the table already exists (and the columns types and ordering line up), you can use: INSERT INTO JmxMonSer SELECT * FROM services WHERE monitoring_enabled=1 回答2: I'm

Alter table if exists or create if doesn't

我怕爱的太早我们不能终老 提交于 2019-11-27 03:09:07
问题 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 because their structure is up to date. How can I make an elegant combination of ALTER and CREATE ? I was thinking there must be something like "ADD... IF... Duplicate" Say I have table A. In one client the table has one column -A1, and another client

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

拜拜、爱过 提交于 2019-11-27 02:58:44
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. From http://www.sqlite.org/lang_createtable.html : CREATE TABLE IF NOT EXISTS some_table (id INTEGER PRIMARY KEY AUTOINCREMENT, ...); 来源: https://stackoverflow.com/questions/4098008/create-table-in-sqlite-only-if-it-doesnt-exist-already

PostgreSQL Error: Relation already exists

烈酒焚心 提交于 2019-11-27 01:44:59
问题 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 exists. I already tried to find it in \dS+ listing all relations, and it is not there. To complicate this, I have tested this by creating this table in another database and I got the same error. I am thinking that could be an error when this table was

PostgreSQL create table if not exists

霸气de小男生 提交于 2019-11-26 19:47:50
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? This feature has been implemented in Postgres 9.1 : CREATE TABLE IF NOT EXISTS myschema.mytable (i integer); For older versions , here is a function to work around it: CREATE OR REPLACE FUNCTION create_mytable () RETURNS void AS $func$ BEGIN IF EXISTS (SELECT 1 FROM pg_catalog.pg_tables WHERE schemaname = 'myschema' AND tablename = 'mytable') THEN RAISE NOTICE 'Table myschema.mytable already exists.'

How do I create a table based on another table [duplicate]

谁说我不能喝 提交于 2019-11-26 19:43:29
问题 This question already has answers here : Try to create a table from Select - SqL Server 2008 throws error (4 answers) Closed 6 years ago . 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. 回答1: There is no such syntax in SQL Server, though CREATE TABLE AS ... SELECT does exist in PDW. In SQL Server you can use