create-table

Create table in by sql statement using executeUpdate in Mysql

点点圈 提交于 2019-11-30 21:16:00
问题 I have the following doGet() : protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { MysqlDataSource ds = new MysqlConnectionPoolDataSource(); ds.setServerName("localhost"); ds.setPort(3306); ds.setUser("root"); ds.setPassword(""); try { Connection connection = null ; connection = ds.getConnection(); Statement statement = connection.createStatement(); // create the DB .. statement.executeUpdate("CREATE DATABASE IF NOT EXISTS " +

How do I alter my existing table to create a range partition in Oracle

给你一囗甜甜゛ 提交于 2019-11-30 20:18:26
I have existing table which has 10 years of data (I have taken dump). I would like to Range partition the existing table on one date key column within the table. Most of the examples I see are with CREATE TABLE..PARTITION BY RANGE... to add new partitions. But my table is existing table. I assume I need some ALTER statement. ALTER TABLE TABLE_NAME PARTITION BY RANGE(CREATED_DATE) PARTITION JAN16 VALUES LESS THAN (01-02-2016), PARTITION FEB16 VALUES LESS THAN (01-03-2016) AND GREATER THAN(31-01-2016),//OR? PARTITION MAR16 VALUES BETWEEN (01-03-2016) AND (31-03-2016), //OR? Two questions.. Do I

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

早过忘川 提交于 2019-11-30 12:01:22
问题 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 tidy thing to do but I cannot see a way. Has anyone managed to do this? 回答1: While you can't do it in CREATE TABLE , you can do it at the same time, in the same database script, using this approach: CREATE table T1 (id int , name char (20)) EXEC sp

How to copy structure of one table to another with foreign key constraints in psql?

泄露秘密 提交于 2019-11-30 09:29:24
Foreign key constraints are not copied when using create table table_name ( like source_table INCLUDING ALL)' in Postgres. How can I create a copy of an existing table including all foreign keys. There is no option to automatically create foreign keys in CREATE TABLE ... LIKE ... . For the documentation: LIKE source_table [ like_option ... ] Not-null constraints are always copied to the new table. CHECK constraints will be copied only if INCLUDING CONSTRAINTS is specified [...] Indexes, PRIMARY KEY, and UNIQUE constraints on the original table will be created on the new table only if the

PostgreSQL: Create table if not exists AS

淺唱寂寞╮ 提交于 2019-11-30 06:13:21
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 AS (....query...) using exactly the same query, I get: ERROR: syntax error at or near "as" Is there any way to do this? CREATE TABLE AS is considered a separate statement from a normal CREATE TABLE , and until Postgres version 9.5 (see changelog entry ) didn't support an IF NOT EXISTS clause. (Be sure to look at the correct version of the manual for the

Postgres table column name restrictions?

泪湿孤枕 提交于 2019-11-30 05:39:43
I did this in psql: CREATE TABLE IF NOT EXISTS apiss (skey TEXT, time INTEGER, user TEXT, ip TEXT); I get ERROR: syntax error at or near "user" LINE 1: ...BLE IF NOT EXISTS apiss (skey TEXT, time INTEGER, user TEXT,... I do: CREATE TABLE IF NOT EXISTS apiss (skey TEXT, time INTEGER, userd TEXT, ip TEXT); It works. Note the userd instead of user. Are there some restrictions on the column names that a table can have? (postgresql v9.1.3) bernie Here's a nice table of reserved words in PostgreSQL: http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html It is probably best to

How do I alter my existing table to create a range partition in Oracle

时光总嘲笑我的痴心妄想 提交于 2019-11-30 03:27:46
问题 I have existing table which has 10 years of data (I have taken dump). I would like to Range partition the existing table on one date key column within the table. Most of the examples I see are with CREATE TABLE..PARTITION BY RANGE... to add new partitions. But my table is existing table. I assume I need some ALTER statement. ALTER TABLE TABLE_NAME PARTITION BY RANGE(CREATED_DATE) PARTITION JAN16 VALUES LESS THAN (01-02-2016), PARTITION FEB16 VALUES LESS THAN (01-03-2016) AND GREATER THAN(31

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

南笙酒味 提交于 2019-11-30 01:52:31
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 tidy thing to do but I cannot see a way. Has anyone managed to do this? While you can't do it in CREATE TABLE , you can do it at the same time, in the same database script, using this approach : CREATE table T1 (id int , name char (20)) EXEC sp_addextendedproperty 'MS_Description', 'Employee ID', 'user', dbo, 'table', 'T1', 'column', id EXEC sp

SQLite Foreign Key

一世执手 提交于 2019-11-29 22:10:22
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 AUTOINCREMENT, checklist_title TEXT, description TEXT, created_on INTEGER, modified_on INTEGER ); CREATE TABLE item ( _id INTEGER PRIMARY KEY AUTOINCREMENT, FOREIGN KEY(checklist_id) REFERENCES checklist(_id), item_text TEXT, item_hint TEXT, item_order INTEGER, created_on INTEGER, modified_on INTEGER ); The first table is made fine. The error occurs in the second

PHP create table error 1064

旧城冷巷雨未停 提交于 2019-11-29 18:37:29
I am trying to create a table in mySQL. This is my php page below, when I run the page there are no errors but the table is not in mySQL and when I test the code in mySQL I'm getting the error #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$user = "root"' at line 1. I've done a bit of research into what this error means but I'm getting no where. I don't really understand what it means. If I'm honest I don't really understand php I'm just adapting the code I've written in previous uni tutorials.