create-table

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

六眼飞鱼酱① 提交于 2019-12-05 00:40:38
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. CREATE TABLE IF NOT EXISTS ... is not a standard SQL code. The thing to do is to check if the table is already in the catalogue. For instance, in Java you may do something like: connection.getMetaData()

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

谁说胖子不能爱 提交于 2019-12-04 23:58:59
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) You don't need to. The primary key is already an index. 来源: https://stackoverflow.com/questions/14646014/do-i-need-to-create-separate-index-for-primary-key-of-relational-database-table

Primary key in cassandra is unique?

浪尽此生 提交于 2019-12-04 22:22:30
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.. 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 key. In your case you can have 2 rows with the same name or with the same surname but not both. By definition

How do I import an array of data into separate rows in a hive table?

纵饮孤独 提交于 2019-12-04 17:31:53
I am trying to import data in the following format into a hive table [ { "identifier" : "id#1", "dataA" : "dataA#1" }, { "identifier" : "id#2", "dataA" : "dataA#2" } ] I have multiple files like this and I want each {} to form one row in the table. This is what I have tried: CREATE EXTERNAL TABLE final_table( identifier STRING, dataA STRING ) ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' LOCATION "s3://bucket/path_in_bucket/" This is not creating a single row for each {} though. I have also tried CREATE EXTERNAL TABLE final_table( rows ARRAY< STRUCT< identifier: STRING, dataA: STRING >

csv file to hive table using load data - How to format the date in csv to accept by hive table

孤者浪人 提交于 2019-12-04 17:17:15
I am using load data syntax to load a csv file to a table.The file is same format as hive accepts. But still after load data is issued, Last 2 columns returns null on select. 1750,651,'2013-03-11','2013-03-17' 1751,652,'2013-03-18','2013-03-24' 1752,653,'2013-03-25','2013-03-31' 1753,654,'2013-04-01','2013-04-07' create table dattable( DATANUM INT, ENTRYNUM BIGINT, START_DATE DATE, END_DATE DATE ) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' ; LOAD DATA LOCAL INPATH '/path/dtatable.csv' OVERWRITE INTO TABLE dattable ; Select returns NULL values for the last 2 cols Other question was what if

Can I dynamically create a mySQL table from JSON?

爷,独闯天下 提交于 2019-12-04 15:23:49
Let's say I have a server side script which generates JSON from a simple select on a table. The JSON is encoded in the 1st script. I have no control over this 1st script, but am aware when the underlying database structure changes and when the JSON structure changes. Script 2 uses CURL to get the .js file (contents) which contains the JSON, I can then decode into an array. What I need to do then is store the data in another database. My question is basically about automating this process and being able to create a table from an array when you don't know what the structure of the array is until

How to create mysql table with column timestamp default current_date?

99封情书 提交于 2019-12-04 09:27:33
问题 I need to create mysql table with default value on column CURRENT_DATE() I try DROP TABLE IF EXISTS `visitors`; CREATE TABLE `visitors` ( `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, `ip` VARCHAR(32) NOT NULL, `browser` VARCHAR(500) NOT NULL, `version` VARCHAR(500) NOT NULL, `platform` ENUM('w','l','m') NOT NULL, `date` TIMESTAMP NOT NULL DEFAULT CURRENT_DATE(), PRIMARY KEY (`id`), UNIQUE KEY `person` (`ip`,`date`) ) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; but it is writting

how to populate database using procedures

不羁的心 提交于 2019-12-04 05:43:56
问题 I have about 15 different Tables filled with different data and different entity relationships. I need to create a script which will populate my database with the content of those tables. After script is finished, i run it in cmd, using sqlplus and later START path to file i have two different sql files, one named db_spec.sql and another db_body.sql. In my db_body.sql i've created a procedure to store data from two tables which have 1:N relationship. First table CREATE TABLE LOCATION ( ID

android sqlite CREATE TABLE IF NOT EXISTS

只愿长相守 提交于 2019-12-03 23:41:50
Having a little problem with creating new tables. When I use the CREATE TABLE command my new tables form as they should, but when I exit the activity the app crashes and I get a TABLE ALREADY EXISTS in the logcat. If I use CREATE TABLE IF NOT EXISTS the new table isn't formed but just adds my new rows of data to a previous table and it doesn't crash. What is wrong with this? I would like to add the table without it giving me the already exists and I would like it to add without it adding rows to a different table. SqliteHelper Class: public class MySQLiteHelper extends SQLiteOpenHelper {

Create new Table in ruby on rails

让人想犯罪 __ 提交于 2019-12-03 23:19:32
I try to create a new table in rails. Every example I find and try sadly does not work with me... so that's what I tried till now: (I use Ruby version 1.9 and Rails Version 3.2.13 making a new model in the terminal: rails generate model content content_id:auto-generated, law_id:integer, parent_id:integer, titel:string, text:string, content:string, url:string that generated following code: class CreateContents < ActiveRecord::Migration def change create_table :contents do |t| t.auto-generated, :content_id t.integer, :law_id t.integer, :parent_id t.string, :titel t.string, :text t.string,