我正在运行的查询如下,但是我收到此错误:
#1054 - 'IN/ALL/ANY子查询'中的未知列'guaranteed_postcode'
SELECT `users`.`first_name`, `users`.`last_name`, `users`.`email`,
SUBSTRING(`locations`.`raw`,-6,4) AS `guaranteed_postcode`
FROM `users` LEFT OUTER JOIN `locations`
ON `users`.`id` = `locations`.`user_id`
WHERE `guaranteed_postcode` NOT IN #this is where the fake col is being used
(
SELECT `postcode` FROM `postcodes` WHERE `region` IN
(
'australia'
)
)
Run Code Online (Sandbox Code Playgroud)
我的问题是:为什么我无法在同一个数据库查询的where子句中使用假列?
为什么在DEFAULT或ON UPDATE子句中只能有一个TIMESTAMP列和CURRENT_TIMESTAMP?
CREATE TABLE `foo` (
`ProductID` INT(10) UNSIGNED NOT NULL,
`AddedDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`UpdatedDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=INNODB;
Run Code Online (Sandbox Code Playgroud)
导致的错误:
错误代码:1293
表定义不正确; 在DEFAULT或ON UPDATE子句中只能有一个TIMESTAMP列和CURRENT_TIMESTAMP
我有以下表架构,它将user_customers映射到实时MySQL数据库的权限:
mysql> describe user_customer_permission;
+------------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_customer_id | int(11) | NO | PRI | NULL | |
| permission_id | int(11) | NO | PRI | NULL | |
+------------------+---------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
我想删除user_customer_id和permission_id的主键,并保留id的主键.
当我运行命令时:
alter table user_customer_permission drop primary key;
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ERROR 1075 (42000): Incorrect table definition; there can …Run Code Online (Sandbox Code Playgroud) 如何使用SQL Server Management Studio创建复合键?
我想要两个INT列来形成表的标识(唯一)
我在mysql中试过这个:
mysql> alter table region drop column country_id;
Run Code Online (Sandbox Code Playgroud)
得到了这个:
ERROR 1025 (HY000): Error on rename of './product/#sql-14ae_81' to
'./product/region' (errno: 150)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?外键的东西?
在处理性能更好的大型数据库时,IN还是OR在SQL Where-clause中?
他们的执行方式有什么不同吗?
我在linux机箱上安装了mysql服务器IP = 192.168.1.100但是当我尝试连接到这个IP时它总是错误(111).但是使用localhost和127.0.0.1就可以了.
beer@beer-laptop# ifconfig | grep "inet addr"
inet addr:127.0.0.1 Mask:255.0.0.0
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
beer@beer-laptop# mysql -ubeer -pbeer -h192.168.1.100
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.100' (111)
beer@beer-laptop# mysql -ubeer -pbeer -hlocalhost
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 160
Server version: 5.1.31-1ubuntu2 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
beer@beer-laptop# mysql -ubeer -pbeer -h127.0.0.1
Welcome to the MySQL … 假设我有两张桌子:
Table: Color
Columns: Id, ColorName, ColorCode
Table: Shape
Columns: Id, ShapeName, VertexList
Run Code Online (Sandbox Code Playgroud)
我该怎么称呼将颜色映射到形状的表格?
Table: ???
Columns: ColorId, ShapeId
Run Code Online (Sandbox Code Playgroud) sql database database-design data-modeling naming-conventions
我有以下表模式;
CREATE TABLE `db1`.`sms_queue` (
`Id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`Message` VARCHAR(160) NOT NULL DEFAULT 'Unknown Message Error',
`CurrentState` VARCHAR(10) NOT NULL DEFAULT 'None',
`Phone` VARCHAR(14) DEFAULT NULL,
`Created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`LastUpdated` TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP,
`TriesLeft` tinyint NOT NULL DEFAULT 3,
PRIMARY KEY (`Id`)
)
ENGINE = InnoDB;
Run Code Online (Sandbox Code Playgroud)
它失败并出现以下错误:
ERROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause.
Run Code Online (Sandbox Code Playgroud)
我的问题是,我可以同时拥有这两个领域吗?或者我必须在每次交易期间手动设置LastUpdated字段?
有没有"简单"的方法来做到这一点,或者我需要传递一个带有"OUTPUT ... INTO"语法的表变量?
DECLARE @someInt int
INSERT INTO MyTable2(AIntColumn)
OUTPUT @SomeInt = Inserted.AIntColumn
VALUES(12)
Run Code Online (Sandbox Code Playgroud) mysql ×6
sql ×5
database ×2
sql-server ×2
t-sql ×2
key ×1
linux ×1
primary-key ×1
ssms ×1
timestamp ×1