create-table

how to use foreign key into new table

I have one table 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 Foriegn Key(id) references GUEST(id), BillNr int(15) not null); what is problem in second command, why it is not working please correct me. it did not create new table...

SQL Create Table Error

Hello all. I am just beginning to learn SQL and have stumbled at the first hurdle, I am unable to create a table. Below is the code example. The error I am receiving when running the statement, references line 7 stating there is an issue with a 'relational operator'. The purpose of line 7 is to check that the age of the person is greater...

Quick SQL question: Correct syntax for creating a table with a primary key in H2?

I'm currently starting a new Java application using the H2 database, but I have some confusion about basic SQL use for creating tables. How do I make a table of entries (strings) each with unique, auto-incrementing, non-null, integer primary keys? One of the most basic things to do, but I'm not sure offhand what the correct way to do i...

Offline MySQL Table Definition Generator

I'm looking for something similar to the table creation form from phpmyadmin, but it should simply display a CREATE TABLE statement in a textarea below the form. It should also not require MySQL, PHP, or even a server to work. I want this for times I'm working on projects and just want to whip up a quick table definition. I'll more than...

MYSQL Create table + Alter table incorrect syntax?

I'm trying to create a table in Navicat and immediately add a foreign key relation after that. The syntax however seems to be incorrect... Is this even possible? CREATE TABLE `Bld` ( `id` int(10) NOT NULL PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `Bld` ( CONSTRAINT `fk_Bld_Bld...

Is there any way for DBUnit to automatically create tables?

I just realized that DBUnit doesn't create tables by itself (see How do I test with DBUnit with plain JDBC and HSQLDB without facing a NoSuchTableException?). Is there any way for DBUnit to automatically create tables from a dataset or dtd? EDIT: For simple testing of an in-memory database like HSQLDB, a crude approach can be used to ...

Problem in Creating Table

Hello All, create table mainTable as select curr_Table.empID as empID, (currTable.ToTalDays-oldTable.ToTalDays) as DiffDays from currTable left outer join oldTable on currTable.empID = oldTable.empID This is the query that i use to find the days worked by an employee. The Problem raises when there is "New Joinee". "oldTable.ToTalDa...

Form has my table locked down tight even after docmd.close

Sorry for the wall of text guys but this one requires expliaining, way too much code to post... I'm importing fixed width files into access in methods that require data entry. I import the file using transferText into two specs (ones global, the other is special circumstance). I have a function that uses DAO to cycle through all Field...

Oracle: LONG RAW to ?

I am writing a program in java where I need to create a copy of a table (without data). for that I am using the following query CREATE TABLE NEW_TABLE AS SELECT * FROM OLD_TABLE I have come across a table where one of the columns has the data type LONG RAW which is depricated. I tried using the query below but it did not work. (ORA-0...

SQL script for creating table

I created a SQL script to create a table. Can you please go through it and see if there are any error, or if there is missing something in that script? Or you can tell me any better idea to create table? use nors go CREATE TABLE t_data_dnefrc ( "RTN", adVarChar, 9 AccountNbr adVarChar(17) PRIMARY KEY, FirstName adVarChar(50), MiddleNa...

Specify PK name during table creation

In MSSQL is there a way to specify a name for a PK constraint so that MSSQL doesn't provide a randomly generated PK name like so: PK__Addresse__3214EC074E88ABD4 The only way I can see to do it now is to first create the table and then issue an ALTER command to rename the PK. It would be easier if I could do it in one shot. ...

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

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? ...

MySQL - How to create a new table that is a join on primary key of two existing tables

Hi All, I have two existing tables, with different fields, except for Primary ID (a varchar, not an int). I want to create a third table which is essentially a merge of these two, such that for a given Primary Key I have all fields in one table. What's the bext way of doing this? Many thanks ...

What's wrong with this SQL Create Table Statement?

This SQL query is generated by SQL Server Managment Studio and it throws me an error: USE [database_name] GO /****** Object: Table [dbo].[UserAddress] Script Date: 02/17/2010 11:21:02 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[UserAddress] ( [ID] [int] IDENTITY(1,1) NOT...

Can ActiveRecord create tables outside of a migration?

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 varcha...

run mysql create table by select another and copied the indexes automatically

i want to run a query like this : CREATE TABLE newtable SELECT * FROM oldtable its work fine but the indexes not copied to the new table , how can i run the query and prevent the indexes ? thanks ...

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

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...

Managing updates with NHibernate

I am aware that you can generate create scripts to generate database objects, but I am looking a way to generate an update script that compares two different schemas (two mapping files). That way I can provide my users with easy database updating from any version to the current version. Thanks! ...

MySQL multi CREATE TABLE syntax help?

Hi guys, I'm trying to write a MySQL script that creates several tables. I have: CREATE TABLE `DataBase1`.`tbl_this`( ... ); CREATE TABLE `DataBase1`.`tbl_that`( ... ); ... (14 more) ... BUT, only the first CREATE TABLE statement is executed. I get no syntax errors. Erm, am I missing the MSSQL equivalent of GO ? What am I doing wro...

Create Table by Copying Structure of Existing Table

I am trying to create a new table by copying an existing table in SQL Server 2008 using Management Studio. The existing table contains no data. I am using the following code but am receiving an error for Incorrect Syntax near AS. I am not sure what is wrong here. I am a SQL newb and any help would be appreciated. Thanks. CREATE TABLE D...