create-table

What's wrong with this SQL Create Table Statement?

别来无恙 提交于 2019-12-10 17:42:17
问题 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 NULL, [UserID] [int] NULL, [AddressName] [nvarchar](25) NULL, [Fname] [nvarchar](15) NULL, [LName] [nvarchar](20) NULL, [City] [nvarchar](15) NULL, [Street] [nvarchar]

SQL Server copy full table definition

隐身守侯 提交于 2019-12-10 16:40:01
问题 In the Enterprise version of SQL Server it is possible to generate the create statement for a pre-existing table by using 'Script Table as', "Create to". This generates the full create statement for the table including indices. Is there any way to do this in T-SQL and therefore be able to copy a table definition to a new table? 回答1: Nothing simply available out of the box in straight T-SQL which exactly replicates what SSMS does. However, you can get to this through the metadata ( INFORMATION

INSERT in TABLES with circular references SQL

依然范特西╮ 提交于 2019-12-10 14:33:48
问题 I have 2 tables: Empleados(**numEmpl**, nombre, apellido, sexo, telefono, salario, numDept) Departamentos(**numDept**, nombreDept, numDirect) In departamentos: numEmpl is primary key numDept is foreign key reference to Departamentos(numDept). In departamentos: numDept is the primary key And numDirect is foreign key reference to Empleados (numEmpl) So there is a circular reference. First of all I created the Tables: CREATE TABLE EMPLEADOS(numEmpl primary key, nombre, apellido, sexo, telefono,

Error with MySQL “CREATE TABLE” query

[亡魂溺海] 提交于 2019-12-10 11:46:37
问题 I know that this has been asked hundreds of times before, but I looked around the Internet and couldn't find what could possibly be wrong with my syntax: mysql_select_db('Projects'); $sql = "CREATE TABLE $data[ID] ( ID INT NOT NULL, Creator INT NOT NULL, Name VARCHAR(20) NOT NULL, Version VARCHAR(20) NOT NULL, Status VARCHAR(20) NOT NULL, Date VARCHAR(20) NOT NULL, Skript VARCHAR(20) NOT NULL, Filename VARCHAR(20) NOT NULL, Downloads INT NOT NULL, PRIMARY KEY(ID) )"; if (mysql_query($sql)){

How to set AUTO_INCREMENT from another table

笑着哭i 提交于 2019-12-10 04:32:18
问题 How can I set the AUTO_INCREMENT on CREATE TABLE or ALTER TABLE from another table? I found this question, but not solved my issue: How to Reset an MySQL AutoIncrement using a MAX value from another table? I also tried this: CREATE TABLE IF NOT EXISTS `table_name` ( `id` mediumint(6) unsigned NOT NULL AUTO_INCREMENT, `columnOne` tinyint(1) NOT NULL, `columnTwo` int(12) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=(SELECT `AUTO_INCREMENT` FROM `INFORMATION

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

江枫思渺然 提交于 2019-12-09 19:29:42
问题 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

SQLITE Query results into a temp table

爷,独闯天下 提交于 2019-12-09 06:20:35
问题 I haven't used SQLite before and can't figure out the syntax, I have this working in SQL Server if it helps. I need to put the results into a temp table so I can reuse them. //SQL Server WITH FT_CTE AS ( SELECT pID, cID FROM brFTNode_Children WHERE pID = 1 UNION ALL SELECT e.pID, e.cID FROM brFTNode_Children e INNER JOIN FT_CTE ftCTE on (ftCTE.cID = e.pID) ) SELECT * INTO #ParentChild FROM FT_CTE; //SQLite try WITH FT_CTE AS ( SELECT pID, cID FROM brFTNode_Children WHERE pID = 1 UNION ALL

How to copy structure and contents of a table, but with separate sequence?

末鹿安然 提交于 2019-12-09 02:49:38
问题 I'm trying to setup temporary tables for unit-testing purposes. So far I managed to create a temporary table which copies the structure of an existing table: CREATE TEMP TABLE t_mytable (LIKE mytable INCLUDING DEFAULTS); But this lacks the data from the original table. I can copy the data into the temporary table by using a CREATE TABLE AS statement instead: CREATE TEMP TABLE t_mytable AS SELECT * FROM mytable; But then the structure of t_mytable will not be identical, e.g. column sizes and

Creating one Table from three different Tables

故事扮演 提交于 2019-12-08 19:14:01
问题 I have three tables in SQL and I need them to all be combined into one. I need all the fields from all the tables in the one table. All the tables contain the same fields just from three different years. I wrote a code that is: CREATE TABLE COL_TBL_TRAINING_ALL_YEARS AS( SELECT COL_TBL_2010_TRN_RESULTS_new.*, COL_TBL_TRN_RESULTS_GEMS_2011.*, COL_TBL_TRN_RESULTS_GEMS_2012.* FROM COL_TBL_2010_TRN_RESULTS_new, COL_TBL_TRN_RESULTS_GEMS_2011, COL_TBL_TRN_RESULTS_GEMS_2012 WHERE COL_TBL_2010_TRN

mySQL Table ERROR 1064

蓝咒 提交于 2019-12-08 14:10:48
问题 CREATE TABLE 'geodata' ( 'Id' char(16) NOT NULL, 'Type' smallint(6) DEFAULT NULL, 'Description' varchar(200) DEFAULT NULL, 'Url' varchar(400) DEFAULT NULL, 'Location' point DEFAULT NULL, PRIMARY KEY ('Id') ); ERROR 1064: 'Id' char(16) NOT NULL, 'Type' smallint(6) DEFAULT NULL, at line1. I don't know whats wrong with my table can someone explain? 回答1: You should replace single quotes with back-ticks i.e `: CREATE TABLE `geodata` ( `Id` char(16) NOT NULL, `Type` smallint(6) DEFAULT NULL,