create-table

Merging two tables into one with the same column names

依然范特西╮ 提交于 2020-01-06 19:50:47
问题 I use this command to merge 2 tables into one: CREATE TABLE table1 AS SELECT name, sum(cnt) FROM (SELECT * FROM table2 UNION ALL SELECT * FROM table3) X GROUP BY name ORDER BY 1; table2 and table3 are tables with columns named name and cnt , but the result table ( table1 ) has the columns name and sum . The question is how to change the command so that the result table will have the columns name and cnt ? 回答1: In the absence of an explicit name, the output of a function inherits the basic

Drop table, then cannot recreate table with the same name

[亡魂溺海] 提交于 2020-01-05 02:29:40
问题 I first drop a table in SQL Server 2008 (after that it shows the message that the command was executed sucessfully). I then tried to create a table with the same name, and it showed me an error. After closing the SSMS window and re opening it it tried to create the table with the same name again and it succeeded. What is going on? 回答1: You can't drop and create the same table in the same batch in sql server see MSDN Their examples use GO to break up the two commands. Semi colon might work,

Drop table, then cannot recreate table with the same name

拜拜、爱过 提交于 2020-01-05 02:29:16
问题 I first drop a table in SQL Server 2008 (after that it shows the message that the command was executed sucessfully). I then tried to create a table with the same name, and it showed me an error. After closing the SSMS window and re opening it it tried to create the table with the same name again and it succeeded. What is going on? 回答1: You can't drop and create the same table in the same batch in sql server see MSDN Their examples use GO to break up the two commands. Semi colon might work,

Is it possible to reference a different column in the same table?

北慕城南 提交于 2020-01-03 08:28:09
问题 If a blog has a 'categories' table such as the following: CREATE TABLE categories ( id INTEGER PRIMARY KEY AUTO_INCREMENT, parent_id INTEGER NOT NULL, name VARCHAR(30) NOT NULL, description TEXT, count INTEGER NOT NULL DEFAULT 0 ); And if the parent_id field is intended to refer to the 'id' field of the categories table, then how could I add a constraint that would ensure that values inserted into parent_id references the id field? I simply want to make sure that only category id values that

postgres: create table in database from the command line

女生的网名这么多〃 提交于 2020-01-01 01:10:34
问题 I am trying to create a table in postgres, but it ends up in the wrong database. Here is what I do: in my sql script initially I create a user and a database, and then a table. Code will explain more: drop database if exists sinfonifry; drop role if exists sinfonifry; -- create the requested sinfonifry user create user sinfonifry createdb createuser password 'some_password'; -- create a sinfonifry database create database sinfonifry owner sinfonifry; DROP TABLE if exists sinf01_host; CREATE

Create table with COUNT ms-access

自闭症网瘾萝莉.ら 提交于 2019-12-31 05:13:09
问题 I have a database and I want to create a table with COUNT function in it. Is it possible ? I have 3 existing tables: Member Feedback Attendance In Feedback table, 2 columns Class_ID, Likes (Class_ID link with the attendance, as each member attend 1 class eg. class 1,2,3,etc. and Likes is for the number of people like the class). In Attendance table, 3 columns: Class_ID Member_ID Non_member_name Now I want to alter Feedback table to add 2 new columns. One to count the number of people attend

Table cannot be created in mysql -Error 1064

倾然丶 夕夏残阳落幕 提交于 2019-12-31 04:05:06
问题 I am trying to create a table in MySQL with the query CREATE TABLE ofRosterGroups ( rosterID BIGINT NOT NULL, rank TINYINT NOT NULL, groupName VARCHAR(255) NOT NULL, PRIMARY KEY (rosterID, rank), INDEX ofRosterGroup_rosterid_idx (rosterID) ); but seems like it is throwing error everytime I made updates too. I don't know what is going wrong with it. Error coming up is You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to

Create table in mysql with one column containing sum of another two columns value

谁说胖子不能爱 提交于 2019-12-28 22:27:23
问题 Is it possible in mysql to create a table with a column that combines two column values? something like this: create table test1 ( number1 int, number2 int, total int DEFAULT (number1+number2) ); or like this : CREATE TABLE `Result` ( `aCount` INT DEFAULT 0, `bCount` INT DEFAULT 0, `cCount` = `aCount` + `bCount` ); 回答1: It is not possible to do that exactly, but you can create a view based on a query that combines them: CREATE VIEW `my_wacky_view` AS SELECT `number1`, `number2`, `number1` +

I cant solve error in database [duplicate]

耗尽温柔 提交于 2019-12-25 18:25:04
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: I have mistake in database create table Ticket ( ticket_id integer not null primary key, AirlineName varchar not null, CustomerName varchar, fromCity varchar, toCity varchar, fltNo integer, TicketDate date, Dtime TIME, Atime time, price integer); Please help me, I can't find the error. the program is my sql, and this is the error You have an error in your SQL syntax; check the manual that corresponds to your

i am migrtaing database from sql server 2008 to teradata

我的未来我决定 提交于 2019-12-25 13:53:11
问题 I am migrating a database from Sql Server 2008 to Teradata and I am facing a problem: In Sql Server in the ddl of a table column is defined as follows: [rowguid] uniqueidentifier ROWGUIDCOL NOT NULL CONSTRAINT [DF_Address_rowguid] DEFAULT (NEWID()) This column uses newid() function to generate and insert random varchar value in the column [rowguid] if the user doesnt provide any input. There is no similar function in Teradata to generate this value. What can be used instead of of NEWID()