I want to create a external table in Qubole similar to a table created in Mysql. Query for create table in mysql is:
CREATE TABLE `mytable` (
`id` varchar(50) NOT NULL,
`v_count` int(11) DEFAULT NULL,
`l_visited` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`f_visited` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
can anyone help me to write similar query in hive.
try this way :
CREATE TABLE page_view(viewTime INT, userid BIGINT,
page_url STRING, referrer_url STRING,
ip STRING COMMENT 'IP Address of the User')
COMMENT 'This is the page view table'
PARTITIONED BY(dt STRING, country STRING)
STORED AS SEQUENCEFILE;
Follow this links:
link1
link2
Related
So I'm trying to migrate a table from MySQL to MSSQL (sql server migration assistant MySQL), but I get this error:
Migrating data...
Analyzing metadata...
Preparing table testreportingdebug.testcase...
Preparing data migration package...
Starting data migration Engine
Starting data migration...
The data migration engine is migrating table '`testreportingdebug`.`testcase`': > [SwMetrics].[testreportingdebug].[testcase], 8855 rows total
Violation of UNIQUE KEY constraint 'testcase$Unique'. Cannot insert duplicate key in object 'testreportingdebug.testcase'. The duplicate key value is (<NULL>, <NULL>).
Errors: Violation of UNIQUE KEY constraint 'testcase$Unique'. Cannot insert duplicate key in object 'testreportingdebug.testcase'. The duplicate key value is (<NULL>, <NULL>).
Completing migration of table `testreportingdebug`.`testcase`...
Migration complete for table '`testreportingdebug`.`testcase`': > [SwMetrics].[testreportingdebug].[testcase], 0 rows migrated (Elapsed Time = 00:00:00:01:352).
Data migration operation has finished.
0 table(s) successfully migrated.
0 table(s) partially migrated.
1 table(s) failed to migrate.
I've just copied three rows from my table, and this is what they look like:
'1', 'Pump# TimeToService', NULL, NULL, 'A general test case comment ...', '0'
'2', 'Config.SlaveMinimumReplyDelay', NULL, NULL, NULL, '0'
'3', 'Config.RESERVED', NULL, NULL, NULL, '0'
If you are wondering how the colons in the MySQL table is setup, here you go:
Is is because right, left and comment can be null?
DDL of table
CREATE TABLE `testcase` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`TestCaseName` varchar(150) DEFAULT NULL,
`Left` int(11) DEFAULT NULL,
`Right` int(11) DEFAULT NULL,
`Comment` text,
`Hidden` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `Unique` (`Left`,`Right`)
) ENGINE=InnoDB AUTO_INCREMENT=10580 DEFAULT CHARSET=utf8
Had to remove the Unique part, since their are only NULL.
ALTER TABLE `testreportingdebug`.`testcase`
DROP INDEX `Unique`;
If you want the strict equivalent in SQL Server of your MySQL table you must create it like this :
CREATE TABLE testcase (
id int NOT NULL IDENTITY PRIMARY KEY,
TestCaseName varchar(150),
[Left] int,
[Right] int,
Comment VARCHAR(max),
[Hidden] tinyint DEFAULT 0,
);
CREATE UNIQUE INDEX X_testcase_right_left
ON testcase ([Left], [Right])
WHERE [Left] IS NOT NULL
AND [Right] IS NOT NULL;
By the way, column names "Right", "left", "hidden" are SQL / MS SQL Server reserved words and should not be used at anytime for SQL identifiers (table name, colum name, proc name...)
The complete list can be obtain here
I have a table which use CURRENT_TIMESTAMP as a default value on column. table working fine. but when export the database and then again import the exported mysql file, then the CURRENT_TIMESTAMP column replace all date with current today datetime.
This is the table srtructure:
CREATE TABLE a (
id int NOT NULL AUTO_INCREMENT,
col0 varchar(5) NOT NULL ,
col1 varchar(10) NOT NULL,
col2 varchar(20) ,
col3 varchar(20) NOT NULL,
createDateTime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id))
ENGINE=InnoDB
AUTO_INCREMENT=7430
DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci
Just replace createDateTime timestamp with createDateTime datetime
I can say that the problem is here:
CREATE TABLE a (
id int NOT NULL AUTO_INCREMENT,
col0 varchar(5) NOT NULL ,
col1 varchar(10) NOT NULL,
col2 varchar(20) ,
col3 varchar(20) NOT NULL,
createDateTime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, <--- **Here
PRIMARY KEY (id))
ENGINE=InnoDB
AUTO_INCREMENT=7430
DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci;
Since you define the createDateTime column with CURRENT_TIMESTAMP as default, whenever there's changes on the row data, the column would update itself.
I experienced this once when I was doing an app and I put my createdDate column as CURRENT_TIMESTAMP default similar as you. Then I realize that every time I made changes on some information through the app, the column also get updated to the current timestamp; which ultimately made my data all messed up!
I think what you can do from the exported file (sql dump) is:
Open the dump file using a text editor - (caveat: if the dump file is too large, might not be easy to open.)
Locate the CREATE TABLE syntax in the dump file then change the following:
CREATE TABLE a (
id int NOT NULL AUTO_INCREMENT,
col0 varchar(5) NOT NULL ,
col1 varchar(10) NOT NULL,
col2 varchar(20) ,
col3 varchar(20) NOT NULL,
createDateTime timestamp NOT NULL, <--- **Here
PRIMARY KEY (id))
ENGINE=InnoDB
AUTO_INCREMENT=7430
DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci;
Save the dump file and try importing it.
If that doesn't work, I suggest:
Create another table using the CREATE TABLE with modified createDateTime column above - name it as a1 or a_copy etc.
Run INSERT query from table A like :
INSERT INTO a_copy SELECT * FROM a;
Check if data matches between the two table - I usually run a LEFT JOIN query for a quick check like this:
SELECT a.id, a_copy.id FROM a
LEFT JOIN a_copy
ON a.id=a_copy.id
AND a.col0=a_copy.col0
AND a.col1=a_copy.col1
AND a.col2=a_copy.col2
AND a.col3=a_copy.col3
AND a.createDateTime=a_copy.createDateTime
WHERE a_copy.id IS NULL;
*The ON condition can be just ON a.id=a_copy.id AND a.createDateTime=a_copy.createDateTime and WHERE a_copy.id IS NULL is just simply showing any result that doesn't match.
Once you're satisfied, export and import the a_copy table.
it seems like my syntax for the following command is incorrect. The error message points to the default current timestamp. Can someone point out where am I going wrong? Your help is much appreciated as I'm working on my first app. My code is the following:
CREATE TABLE ingredients (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
ingredient VARCHAR(100),
created_at DEFAULT CURRENT_TIMESTAMP,
updated_at DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
You forgot the Data Type ;)
The correct Query is following:
CREATE TABLE ingredients (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
ingredient VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
Check out the docs: MySQL Docs | Create Table
You can check your syntax with following tool: SQL Validator
I need to create a database to store some logs which can occurs once per millisecond.
I've created the following table:
CREATE TABLE `log` (
`DataEvento` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
`CodiceEvento` int(11) NOT NULL,
`IdApplicativo` int(11) NOT NULL,
PRIMARY KEY (`DataEvento`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
And a stored procedure:
CREATE DEFINER=`root`#`localhost` PROCEDURE `ScriviEvento`(IN evt_id INT, IN app_id INT, IN evt_descr TEXT)
BEGIN
DECLARE timestamp_now TIMESTAMP(3) DEFAULT NOW(3);
INSERT INTO log (DataEvento, CodiceEvento, IdApplicativo) VALUES (timestamp_now, evt_id, app_id);
IF (LENGTH(evt_descr) > 0) THEN
INSERT INTO descrizionelog (DataEvento, DescrizioneEvento) VALUES (timestamp_now, evt_descr);
END IF;
END
Inserting manually some entries I get the correct timestamp with milliseconds but if I create a thread
with a Sleep(1) I got duplicate key error, same happens if I press execute button fast in workbench with
CALL(1, 0, '');
Is there a workaround to this (excluding using an auto-increment id), or am I doing something wrong?
You are doing something wrong by assuming that the timestamp is going to be unique for log records. That really doesn't make sense.
I'm not sure why you are opposed to an auto-increment solution. This would be the right approach:
CREATE TABLE `log` (
LogId int auto_increment primary key,
`DataEvento` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
`CodiceEvento` int NOT NULL,
`IdApplicativo` int NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
I am trying to add a column to a table.To do so I am trying
ALTER TABLE requirements Modify COLUMN parent_id int(11);
but when I try to execute this query mysql does not respond for long.So each time I have to kill the query.
I have created the table using
CREATE TABLE requirements (requirement_id smallint(6) NOT NULL AUTO_INCREMENT,
product_id smallint(6) NOT NULL,
name varchar(255) CHARACTERSET latin1 NOT NULL DEFAULT '',
PRIMARY KEY (requirement_id),
UNIQUE KEY requirement_product_id_name_idx (product_id,name),
UNIQUE KEY requirement_product_idx (requirement_id,product_id),
KEY requirement_name_idx_v2 (name) )
ENGINE=InnoDB
AUTO_INCREMENT=7365
DEFAULT CHARSET=utf8;
Please help me know why I am not able to execute the Alter table query.I am new to database is there something wrong with my alter table query.
According to your table defintion parent_id seems to be a new column which you want to add so your query should be to add the column not modify.
Try this:
alter table requirements add column parent_id int(11);
SQL FIDDLE DEMO
On a side note:
There needs to be a space between CHARACTERSET here
name varchar(255) CHARACTERSET latin1 NOT NULL DEFAULT '',
should be
name varchar(255) CHARACTER SET latin1 NOT NULL DEFAULT '',