我正在寻找一种暂时关闭所有数据库约束(例如表关系)的方法.
我需要将一个DB的表复制(使用INSERT)到另一个DB.我知道我可以通过以正确的顺序执行命令(不破坏关系)来实现这一点.
但是如果我可以暂时关闭检查约束并在操作完成后重新打开它会更容易.
这可能吗?
sql sql-server entity-relationship sql-server-2005 constraints
如果Postgres表中的列具有名称year,那么应该如何INSERT查询以设置该列的值?
例如:INSERT INTO table (id, name, year) VALUES ( ... );在年份字附近给出错误.
网站"如何计算MySQL数据库大小"给出了两个查询:
确定所有数据库的大小
SELECT table_schema "Data Base Name", SUM( data_length + index_length) / 1024 / 1024
"Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema ;
Run Code Online (Sandbox Code Playgroud)
确定数据库中所有表的大小
SELECT TABLE_NAME, table_rows, data_length, index_length,
round(((data_length + index_length) / 1024 / 1024),2) "Size in MB"
FROM information_schema.TABLES WHERE table_schema = "schema_name";
Run Code Online (Sandbox Code Playgroud)
第一个查询正常工作,但第二个查询不生成结果集.它只显示没有任何行的字段的名称.如何修改第二个查询以正确显示数据库中表格大小的大小.
例如,mysql引用表名使用
SELECT * FROM `table_name`;
Run Code Online (Sandbox Code Playgroud)
注意`
其他数据库是否使用不同的char来引用其表名
我在sql server 2008中添加了一个字段,它将列名放在括号中[column2],但是其他列名没有括号.括号是什么意思?
这个专栏是 [macro-writer]
我应该删除减号并用下划线替换?
我有字段firstname和lastname我的MySQL表.为方便起见,我想在我的Doctrine 2实体中添加一个计算列full_name.在普通的MySQL中我会做这样的事情
SELECT CONCAT(firstname, " ", lastname) AS full_name FROM customers;
Run Code Online (Sandbox Code Playgroud)
但是,连接字段和常量字符串(在这种情况下为"")似乎不适用于Doctrine的CONCAT实现.使用以下代码时
$repository
->createQueryBuilder('customer')
->select('CONCAT(customer.firstname, " ", customer.lastname) AS full_name')
// ...
Run Code Online (Sandbox Code Playgroud)
我收到了错误
[Syntax Error] line 0, col 91: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression, got '"'
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现与MySQL相同的行为?
我试图找出为什么我无法使用 psycopg2 访问 PostgreSQL 数据库中的特定表。我正在运行 PostgreSQL 11.5
如果这样做,我可以连接到相关数据库并读取其中的所有表:
import psycopg2
try:
connection = psycopg2.connect(user = "postgres", #psycopg2.connect() creates connection to PostgreSQL database instance
password = "battlebot",
host = "127.0.0.1",
port = "5432",
database = "BRE_2019")
cursor = connection.cursor() #creates a cursor object which allows us to execute PostgreSQL commands through python source
#Print PostgreSQL version
cursor.execute("""SELECT table_name FROM information_schema.tables
WHERE table_schema = 'public'""")
for table in cursor.fetchall():
print(table)
Run Code Online (Sandbox Code Playgroud)
结果如下:
('geography_columns',)
('geometry_columns',)
('spatial_ref_sys',)
('raster_columns',)
('raster_overviews',)
('nc_avery_parcels_poly',)
('Zone5e',)
('AllResidential2019',)
#....etc....
Run Code Online (Sandbox Code Playgroud)
我感兴趣的表是最后一个表“AllResidential2019”
因此,我尝试连接到它并通过执行以下操作来打印内容: …
我正在使用postgresql,并且尝试将数据插入表中users。当我这样做时
INSERT INTO users(user_name, name, password,email) VALUES ("user2","first last","password1", "user2@gmail.com" );
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ERROR: column "user2" does not exist
Run Code Online (Sandbox Code Playgroud)
这是表格的样子。
Table "public.users"
Column | Type | Modifiers
user_name | character varying(50) |
name | character varying(50) |
password | character varying(50) |
email | character varying(100) |
user_id | integer | not null default nextval('users_user_id_seq'::regclass)
Indexes:
"users_pkey" PRIMARY KEY, btree (user_id)
Run Code Online (Sandbox Code Playgroud)
我可以插入一行,但现在无法正常工作。
我没有看到使用单引号或双引号有任何区别.什么时候或为什么我应该使用第一个而不是后者?
我已经阅读了一些针对SQL的地方我应该使用单打 - 为什么?
我想通过sql查询获得Oracle starttime.我使用这个SQL语句
SQL_Statement = "select to_char(startup_time, 'HH24:MI DD-MON-YY') "Startup time" from v$instance";
Run Code Online (Sandbox Code Playgroud)
当我尝试使用此SQL语句编写代码时,引号存在问题.编写此SQL语句的正确方法是什么?
最好的祝愿
PS我使用Java.当我尝试运行此SQL查询时:
select to_char(startup_time, 'HH24:MI DD-MON-YY') 'Startup time' from v$instance
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Error starting at line 1 in command:
select to_char(startup_time, 'HH24:MI DD-MON-YY') 'Startup time' from v$instance
Error at Command Line:1 Column:50
Error report:
SQL Error: ORA-00923: FROM keyword not found where expected
00923. 00000 - "FROM keyword not found where expected"
*Cause:
*Action:
Run Code Online (Sandbox Code Playgroud) 我发现了问题,现在我的插入查询有效,但我不明白为什么.这是我当前的工作查询:
$add_movie = mysql_query("INSERT INTO ownedmovies VALUES ('', '{$movie_data['Title']}',
'{$movie_data['Year']}', '{$movie_data['Rated']}', '{$movie_data['Runtime']}',
'{$movie_data['Genre']}', '{$movie_data['Director']}', '{$movie_data['Writer']}',
'{$movie_data['Actors']}', \"{$movie_data['Plot']}\", '{$movie_data['imdbRating']}')");
Run Code Online (Sandbox Code Playgroud)
请注意,我在绘图字段周围使用了双引号,而在其他所有内容中使用了正常.当我以与其他人相同的方式绘制绘图字段时,它不会出错但是没有任何内容会插入到表格中......现在它完美无缺.
有人可以告诉我为什么会这样吗?
谢谢
sql ×6
mysql ×5
postgresql ×3
database ×2
php ×2
sql-server ×2
concat ×1
constraints ×1
doctrine-orm ×1
java ×1
oracle ×1
psycopg2 ×1
python ×1
python-3.x ×1
string ×1