create-table

Set default value in column IF condition is met in SQL 2008

这一生的挚爱 提交于 2019-12-08 12:55:33
First of all, I'm very new with SQL query, so I apologize if I sound ignorant... I have a database that has a stored job to drop and create a table every hour. The table looks like this, except there is data for every hour in between 1 and 24 Name Hour1 Hour24 Point 1 OUT 4 5 Point 1 IN 26 22 Point 2 OUT 46 44 Point 2 IN 0 0 Point 3 OUT 18 19 Point 3 IN 56 51 Point 4 OUT 111 100 Point 4 IN 0 0 Point 5 OUT 0 0 Point 5 IN 42 46 Point 6 IN 210 211 After the drop and create, the database adds a column at the end called date and sets todays date as the default. My problem is when importing the data

MySql tables, error #1064 & error #1068 Multiple primary key defined [closed]

Deadly 提交于 2019-12-08 08:48:47
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I have got errors when I tried to install the MySql tables, error: "#1064 - You have an error in your SQL syntax" and error: "#1068 - Multiple primary

Set default value in column IF condition is met in SQL 2008

寵の児 提交于 2019-12-08 08:43:27
问题 First of all, I'm very new with SQL query, so I apologize if I sound ignorant... I have a database that has a stored job to drop and create a table every hour. The table looks like this, except there is data for every hour in between 1 and 24 Name Hour1 Hour24 Point 1 OUT 4 5 Point 1 IN 26 22 Point 2 OUT 46 44 Point 2 IN 0 0 Point 3 OUT 18 19 Point 3 IN 56 51 Point 4 OUT 111 100 Point 4 IN 0 0 Point 5 OUT 0 0 Point 5 IN 42 46 Point 6 IN 210 211 After the drop and create, the database adds a

SQL Error - missing keyword

一笑奈何 提交于 2019-12-07 22:09:08
问题 Whats wrong with this query : I am getting following error SQL Error: ORA-00905: missing keyword 00905. 00000 - "missing keyword" it says error at 4th row. Please advise CREATE TABLE ORDERS ( ID INT NOT NULL, ord_date DATE, AMOUNT double, CUSTOMER_ID INT references CUSTOMERS(ID), PRIMARY KEY (ID) ); 回答1: You missed to add precision in double datatype CREATE TABLE ORDERS ( ID INT NOT NULL, ord_date DATE, AMOUNT double precision, CUSTOMER_ID INT references CUSTOMERS(ID), PRIMARY KEY (ID) );

Informix equivalent to mysql's SHOW CREATE TABLE

蓝咒 提交于 2019-12-07 15:06:54
问题 Is there any equivalent to MySQL's SHOW CREATE TABLE <tablename> in informix? I would like to run it in the SQL Manager on the Server Studio and would also like to obtain information about a tables columns and their types. Is this possible? I've found the systables, syscolumns and information schema, but wasn't lucky with the results I got with the output of select * from... . 回答1: I don't know such SQL command. From command line you can use dbschema utility: C:\Informix>dbschema -t abc -d

PostgreSQL - Create table and set specific date format

天大地大妈咪最大 提交于 2019-12-07 05:40:17
问题 I want to create a new table and set a date type with a specific format. Is that possible? For example: CREATE TABLE User ( ... EXPIRATION DATE " YYYY/MM" ... ) 回答1: I suggest a different approach: Never store date / time as character type ( text , varchar() , ...) to begin with. Use an appropriate type, probably date in your case. Also, never use reserved words as identifier. user is just not possible to begin with, you would have to double-quote, which I would discourage. Could look like

“Create table if not exists” - how to check the schema, too?

匆匆过客 提交于 2019-12-06 19:14:30
问题 Is there a (more or less) standard way to check not only whether a table named mytable exists, but also whether its schema is similar to what it should be? I'm experimenting with H2 database, and CREATE TABLE IF NOT EXISTS mytable (....) statements apparently only check for the table´s name . I would expect to get an exception if there's a table with the given name, but different schema. 回答1: CREATE TABLE IF NOT EXISTS ... is not a standard SQL code. The thing to do is to check if the table

Create a temporary table from a selection or insert if table already exist

孤者浪人 提交于 2019-12-06 18:35:06
问题 What is the best way to create a temporary table, if it does not already exist, and add the selected rows to it? 回答1: CREATE TABLE AS is the simplest and fastest way: CREATE TEMP TABLE tbl AS SELECT * FROM tbl WHERE ... ; Not sure whether table already exists CREATE TABLE IF NOT EXISTS ... was introduced in version Postgres 9.1. For older versions, use the function provided in this related answer: PostgreSQL create table if not exists Then: INSERT INTO tbl (col1, col2, ...) SELECT col1, col2,

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

偶尔善良 提交于 2019-12-06 18:29:44
问题 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 I also need to do CREATE INDEX release_idx ON release(guid) or not (I'm using Derby a database that comes with Java) 回答1: You don't need to. The primary key is already an index. 来源: https://stackoverflow.com/questions/14646014/do-i-need-to-create

Primary key in cassandra is unique?

你。 提交于 2019-12-06 16:44:49
问题 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 database to have 2 persons in my database with the same name and surname but different ages? Which means same primary key.. 回答1: Yes the primary key has to be unique. Otherwise there would be no way to know which row to return when you query with a duplicate