我从来没有为SQL Server"手动编码"对象创建代码,并且外键修改在SQL Server和Postgres之间看似不同.这是我的sql到目前为止:
drop table exams;
drop table question_bank;
drop table anwser_bank;
create table exams
(
exam_id uniqueidentifier primary key,
exam_name varchar(50),
);
create table question_bank
(
question_id uniqueidentifier primary key,
question_exam_id uniqueidentifier not null,
question_text varchar(1024) not null,
question_point_value decimal,
constraint question_exam_id foreign key references exams(exam_id)
);
create table anwser_bank
(
anwser_id uniqueidentifier primary key,
anwser_question_id uniqueidentifier,
anwser_text varchar(1024),
anwser_is_correct bit
);
Run Code Online (Sandbox Code Playgroud)
当我运行查询时,我收到此错误:
消息8139,级别16,状态0,行9外键中的引用列数与引用列的数量不同,表'question_bank'.
你能发现错误吗?
我已经通过以下方式创建了一个外键(在SQL Server中):
alter table company add CountryID varchar(3);
alter table company add constraint Company_CountryID_FK foreign key(CountryID)
references Country;
Run Code Online (Sandbox Code Playgroud)
然后我运行此查询:
alter table company drop column CountryID;
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
消息5074,级别16,状态4,行2
对象'Company_CountryID_FK'依赖于列'CountryID'.
消息4922,级别16,状态9,行2
ALTER TABLE DROP COLUMN CountryID失败,因为一个或多个对象访问此列
我试过这个,但它似乎不起作用:
alter table company drop foreign key Company_CountryID_FK;
alter table company drop column CountryID;
Run Code Online (Sandbox Code Playgroud)
删除CountryID列需要做什么?
谢谢.
作为" 什么是索引以及如何使用它们来优化我的数据库中的查询? " 的后续内容,我试图了解索引,哪些列是好的索引候选者?专门针对MS SQL数据库?
经过一些谷歌搜索,我读过的所有内容都表明,通常增加和唯一的列会产生一个很好的索引(比如MySQL的auto_increment),我理解这一点,但我使用的是MS SQL,我使用GUID作为主键,所以看来索引不会使GUID列受益......
我按照这里的说明操作:http://crazytoon.com/2007/07/23/mysql-changing-runtime-variables-with-out-restarting-mysql-server/但似乎只设置了阈值.
我是否需要做其他任何事情,例如设置文件路径?
根据MySQL的文档
If no file_name value is given for --log-slow-queries, the default name is host_name-slow.log. The server creates the file in the data directory unless an absolute path name is given to specify a different directory.
运行
SHOW VARIABLES
不指示任何日志文件路径,我在我的服务器上看不到任何慢查询日志文件...
编辑
看起来我正在使用服务器版本5.0.77,所以我需要这样做:
SET GLOBAL log_slow_queries = 1;
但我得到:ERROR 1238(HY000):变量'log_slow_queries'是一个只读变量
我假设我需要重新启动服务器并在我的配置中设置log_slow_queries?
我想做这样的事情:
create table app_users
(
app_user_id smallint(6) not null auto_increment primary key,
api_key char(36) not null default uuid()
);
但是这会导致错误,有没有办法在mysql中调用函数作为默认值?
谢谢.
我有一个.NET webform,它有一个与正则表达式验证器绑定的文件上传控件.此验证程序需要验证是否只允许上传某些文件类型(jpg,gif,doc,pdf)
执行此操作的当前正则表达式为:
^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.jpg|.JPG|.gif|.GIF|.doc|.DOC|.pdf|.PDF)$
然而,这似乎并没有起作用......任何人都可以给我一点注册帮助吗?
谢谢.
如何在PHP中动态调用类方法?类方法不是静态的.看起来
call_user_func(...)
Run Code Online (Sandbox Code Playgroud)
仅适用于静态功能?
谢谢.
C#是否具有私有/受保护继承的概念,如果没有,为什么?
C++
class Foo : private Bar {
public:
...
};
C#
public abstract NServlet class : private System.Web.UI.Page
{
// error "type expected"
}
我在.aspx页面中实现了一个"servlet like"概念,我不希望具体类能够看到System.Web.UI.Page基础的内部.
以下代码将无法编译:
string foo = "bar";
Object o = foo == null ? DBNull.Value : foo;
Run Code Online (Sandbox Code Playgroud)
我得到:错误1无法确定条件表达式的类型,因为'System.DBNull'和'string'之间没有隐式转换
要解决这个问题,我必须做这样的事情:
string foo = "bar";
Object o = foo == null ? DBNull.Value : (Object)foo;
Run Code Online (Sandbox Code Playgroud)
这个演员似乎毫无意义,因为这肯定是合法的:
string foo = "bar";
Object o = foo == null ? "gork" : foo;
Run Code Online (Sandbox Code Playgroud)
在我看来,当三元分支具有不同类型时,编译器不会将值自动提供给类型对象...但是当它们属于相同类型时,则自动装箱是自动的.
在我看来,第一个声明应该是合法的......
任何人都可以描述为什么编译器不允许这样做以及为什么C#的设计者选择这样做?我相信这在Java中是合法的......虽然我没有验证这一点.
谢谢.
编辑:我要求理解为什么Java和C#以不同的方式处理这个问题,C#中的场景下发生了什么使得它无效.我知道如何使用三元,而不是寻找一个"更好的方法"来编写示例代码.我理解C#中的三元规则,但我想知道为什么......
编辑(Jon Skeet):删除了"autoboxing"标签,因为这个问题没有涉及拳击.
当我使用base64编码时,PHP在创建图像文件(PNG)时的正确方法是什么?
我一直在玩:
file_put_contents('/tmp/'. $_REQUEST['id'].'.png', $_REQUEST['data']);
我需要解码吗?我应该使用gd库吗?