create-table

Getting an ORA - 00907 error on the following at ON UPDATE

為{幸葍}努か 提交于 2019-11-29 17:01:26
When implementing my oracle database I receive an ORA-00907 error on line 8 at ON UPDATE. Its complaining about right parenthesis but I don't see this error anywhere. whats my issue? CREATE TABLE Result ( Rid number, Hid number, Jid number, Jweight number(5), Place number(3), CONSTRAINT Result_PK PRIMARY KEY(Rid, Hid, Jid), CONSTRAINT ResultRACE_FK FOREIGN KEY(Rid) REFERENCES Race(Rid) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT ResultHORSE_FK FOREIGN KEY(Hid) REFERENCES Horse(Hid) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT ResultJOCKEY_FK FOREIGN KEY(Jid) REFERENCES Jockey(Jid) ON

Column name or number of supplied values does not match table definition from SQL server

三世轮回 提交于 2019-11-29 16:27:01
I get this error when I try to generate data for my database: Column name or number of supplied values does not match table definition This is the structure of my database: Create database Newsagents; USE Newsagents; CREATE TABLE Client ( ClientID int NOT NULL, Name char(30) NOT NULL, City char(20) DEFAULT NULL, Type VARCHAR(15) NOT NULL CHECK (type IN('Individual', 'Company')) PRIMARY KEY (ClientID) ) ; CREATE TABLE Product ( ProductNumber char(10) NOT NULL, ProductName char(20) NOT NULL, Price float NOT NULL, isAvailable tinyint NOT NULL, PRIMARY KEY (ProductNumber) ) ; CREATE TABLE Sales (

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

廉价感情. 提交于 2019-11-29 13:59:59
问题 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. 回答1: 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,

create SQL Server table based on a user defined type

两盒软妹~` 提交于 2019-11-29 09:28:32
I have my defined table type created with CREATE TYPE dbo.MyTableType AS TABLE ( Name varchar(10) NOT NULL, ValueDate date NOT NULL, TenorSize smallint NOT NULL, TenorUnit char(1) NOT NULL, Rate float NOT NULL PRIMARY KEY (Name, ValueDate, TenorSize, TenorUnit) ); and I would like to create a table of this type. From this answer the suggestion was to try CREATE TABLE dbo.MyNewTable AS dbo.MyTableType which produced the following error message in my SQL Server Express 2012: Incorrect syntax near the keyword 'OF'. Is this not supported by SQL Server Express? If so, could I create it some other

How can I add a foreign key when creating a new table?

荒凉一梦 提交于 2019-11-29 06:23:33
I have these two CREATE TABLE statements: CREATE TABLE GUEST ( id int(15) not null auto_increment PRIMARY KEY, GuestName char(25) not null ); CREATE TABLE PAYMENT ( id int(15) not null auto_increment Foreign Key(id) references GUEST(id), BillNr int(15) not null ); What is the problem in the second statement? It did not create a new table. DOK The answer to your question is almost the same as the answer to this one . You need to specify in the table containing the foreign key the name of the table containing the primary key, and the name of the primary key field (using "references"). This has

Postgres table column name restrictions?

血红的双手。 提交于 2019-11-29 02:09:09
问题 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) 回答1: Here's a nice table of reserved words in PostgreSQL:

Can ActiveRecord create tables outside of a migration?

六月ゝ 毕业季﹏ 提交于 2019-11-29 00:46:58
问题 I am working on a non Rails web app, so no migrations script by default. The Sequel ORM lets me create tables easily in a script: #!/usr/bin/env ruby require 'rubygems' require 'sequel' ## Connect to the database DB = Sequel.sqlite('./ex1.db') unless DB.table_exists? :posts DB.create_table :posts do primary_key :id varchar :title text :body end end Is there a way todo this with ActiveRecord outside of migrations? 回答1: My current understanding is no, all modifications data or schema have to be

Copy a MySQL table including indexes

一曲冷凌霜 提交于 2019-11-28 20:02:20
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? raveren CREATE TABLE newtable LIKE oldtable; INSERT newtable SELECT * FROM oldtable; 来源: https://stackoverflow.com/questions/2415855/copy-a-mysql-table-including-indexes

Cannot create a new table after “DROP SCHEMA public”

℡╲_俬逩灬. 提交于 2019-11-28 19:09:22
Since I wanted to drop some tables and somebody suggested the below and I did it: postgres=# drop schema public cascade; DROP SCHEMA postgres=# create schema public; CREATE SCHEMA Then I got problem when creating a new database, such as: postgres=# create database test; CREATE DATABASE postgres=# \c test You are now connected to database "test" as user "postgres". test=# create table hi(id int primary key); *ERROR: no schema has been selected to create in* You can see I got error ERROR: no schema has been selected to create in* How can I restore the public schema? I suggest people never do

PHP MySQL - Error: No Database selected

本小妞迷上赌 提交于 2019-11-28 14:16:16
问题 I am trying to read and write to a database. Here is the code I have so far: $mysql = mysqli_connect("example.com", "johndoe", "abc123"); // replace with actual credidentials $sql = "CREATE DATABASE IF NOT EXISTS dbname"; if (!mysqli_query($mysql, $sql)) { echo "Error creating database: " . mysqli_error($mysql); } if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_close($mysql); $mysql = mysqli_connect("example.com", "johndoe", "abc123",