database-schema

Differences between key, superkey, minimal superkey, candidate key and primary key

删除回忆录丶 提交于 2019-11-27 04:57:18
问题 I'm new to MySQL, and I'm really confused about the different terms that I've encountered. I tried googling the answer but the results are really confusing and when I try and understand it just seems like they are the same thing. What exactly are the differences among key, superkey, minimal superkey, candidate key and primary key? 回答1: Here I copy paste some of the information that I have collected Key A key is a single or combination of multiple fields. Its purpose is to access or retrieve

Dynamically changing schema in Entity Framework Core

天涯浪子 提交于 2019-11-27 04:30:18
问题 UPD here is the way I solved the problem. Although it's likely to be not the best one, it worked for me. I have an issue with working with EF Core. I want to separate data for different companies in my project's database via schema-mechanism. My question is how I can change the schema name in runtime? I've found similar question about this issue but it's still unanswered and I have some different conditions. So I have the Resolve method that grants the db-context when necessary public static

mysqldump - Export structure only without autoincrement

て烟熏妆下的殇ゞ 提交于 2019-11-27 04:13:11
问题 I have a MySQL database and I am trying to find a way to export its structure only, without the auto increment values. mysqldump --no-data would almost do the job, but it keeps the auto_increment values. Is there any way to do it without using PHPMyAdmin (that I know it can do it)? 回答1: You can do this : mysqldump -u root -p -h <db-host> --opt <db-name> -d --single-transaction | sed 's/ AUTO_INCREMENT=[0-9]*\b//' > <filename>.sql As mentioned by others, If you want sed to works properly, add

Is there a way to get a schema of a database from within python?

允我心安 提交于 2019-11-27 02:35:12
问题 I'm trying to find out a way to find the names of tables in a database(if any exist). I find that from a sqlite cli I can use: >.tables Then for the fields: >PRAGMA TABLE_INFO(table_name) This obviously doesn't work within python. Is there even a way to do this with python or should I just be using the sqlite command-line? 回答1: You should be able access the table names from the sqlite_master table. SELECT name FROM sqlite_master WHERE type='table'; The names of the columns are not directly

How do I show the schema of a table in a MySQL database?

拜拜、爱过 提交于 2019-11-27 02:35:00
From the MySQL console, what command displays the schema of any given table? describe [db_name.]table_name; for formatted output, or show create table [db_name.]table_name; for the SQL statement that can be used to create a table. SHOW CREATE TABLE yourTable; or SHOW COLUMNS FROM yourTable; You can also use shorthand for describe as desc for table description. desc [db_name.]table_name; or use db_name; desc table_name; You can also use explain for table description. explain [db_name.]table_name; See official doc Will give output like: +----------+-------------+------+-----+---------+-------+ |

What is the best database schema to support values that are only appropriate to specific rows?

ε祈祈猫儿з 提交于 2019-11-27 01:38:03
I have a db table called Calendar with fields Id (PK) Name Description CalendarTypeId (FK into CalendarType table) I have another table called CalendarType with fields Id (PK) Name Description The issue is that i need to store an additional field for every calendar where the calendar Type is 2. (but this field would be irrelevant for any other calendar type). Should i just create a new field in the Calendar table and ignore that field for all other calendar that have a different calendarTypeid or is there a better way to organize this schema to support this need. Ok, this is the ER model of

Why use a 1-to-1 relationship in database design?

孤街醉人 提交于 2019-11-27 01:34:52
I am having a hard time trying to figure out when to use a 1-to-1 relationship in db design or if it is ever necessary. If you can select only the columns you need in a query is there ever a point to break up a table into 1-to-1 relationships. I guess updating a large table has more impact on performance than a smaller table and I'm sure it depends on how heavily the table is used for certain operations (read/ writes) So when designing a database schema how do you factor in 1-to-1 relationships? What criteria do you use to determine if you need one, and what are the benefits over not using one

Is it possible to create a column with a UNIX_TIMESTAMP default in MySQL?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 00:40:09
问题 I'm trying to do this, but it seems like MySQL isn't allowing me. Is there a solution to this issue or am I expected to always include the function in my INSERT queries? CREATE TABLE foo( created INT NOT NULL DEFAULT UNIX_TIMESTAMP() ) I'm aware of the TIMESTAMP type that accepts a CURRENT_TIMESTAMP default, but my client insisted on using epoch time in the database. 回答1: The way MySQL implements the TIMESTAMP data type, it is actually storing the epoch time in the database. So you could just

DB2 Query to retrieve all table names for a given schema

ぐ巨炮叔叔 提交于 2019-11-27 00:21:04
问题 I'm just looking for a simple query to select all the table names for a given schema. For example, our DB has over 100 tables and I need to find any table that contains the sub-string “CUR”. I can use the like command once I have all the tables. 回答1: select * from sysibm.systables where owner = 'SCHEMA' and name like '%CUR%' and type = 'T'; This will give you all the tables with CUR in them in the SCHEMA schema. See here for more details on the SYSIBM.SYSTABLES table. If you have a look at

How to find column names for all tables in all databases in SQL Server

主宰稳场 提交于 2019-11-27 00:05:15
I want to find all column names in all tables in all databases . Is there a query that can do that for me? The database is Microsoft SQL Server 2000. KM. Try this: select o.name,c.name from sys.columns c inner join sys.objects o on c.object_id=o.object_id order by o.name,c.column_id With resulting column names this would be: select o.name as [Table], c.name as [Column] from sys.columns c inner join sys.objects o on c.object_id=o.object_id --where c.name = 'column you want to find' order by o.name,c.name Or for more detail: SELECT s.name as ColumnName ,sh.name+'.'+o.name AS ObjectName ,o.type