database-schema

Search column name having specific value in tables in certain database

时光怂恿深爱的人放手 提交于 2019-12-06 02:59:08
Is there any way I can search a column having specific value I am trying to find through all tables in a database? For example I have SELECT t.name AS table_name, SCHEMA_NAME(schema_id) AS schema_name, c.name AS column_name FROM sys.tables AS t INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID WHERE c.name LIKE '%VersionID%' ORDER BY schema_name, table_name; Which I found from searching. It gives me the table names that "versionID" column exists, but how can I search to return table names that for example have a value of "35" for that column. Thanks in advance, I apologize, maybe I am not

How to set up Primary Keys in a Relation?

二次信任 提交于 2019-12-06 00:03:39
I wish to know how to correctly set up Primary Keys in a Relation . E.g. we have ER-diagram which contain elements: Key attributes Weak key attributes Identifying relationships Associative entities In order to translate it into Relational Model we should do some tricks. All elements above deal with Primary Keys of relations but they all are Natural Keys - so we can leave them as is or replace with Surrogate Keys . Consider some cases. Case 1 Key Attribute is a name - so it must be of type CHAR or VARCHAR . Generally names become Key Attributes . Case 2 Two (or more) Identifying Relationships

should this database table be normalized?

孤人 提交于 2019-12-05 15:42:09
i have taken over a database that stores fitness information and we were having a debate about a certain table and whether it should stay as one table or get broken up into three tables. Today, there is one table called: workouts that has the following fields id, exercise_id, reps, weight, date, person_id So if i did 2 sets of 3 different exercises on one day, i would have 6 records in that table for that day. for example: id, exercise_id, reps, weight, date, person_id 1, 1, 10, 100, 1/1/2010, 10 2, 1, 10, 100, 1/1/2010, 10 3, 1, 10, 100, 1/1/2010, 10 4, 2, 10, 100, 1/1/2010, 10 5, 2, 10, 100,

How to query table data by Object Id and Column Id?

一笑奈何 提交于 2019-12-05 13:53:22
Having the table Clients . PK LastName Name Address 1 Vidal Arturo St.... 2 Lavezzi Ezequiel St.... 3 Cuadrado Guillermo St.... I want to get: With the following query gives me the first four columns but how can I link this with the table data? SELECT TAB.object_id OBEJCTID, TAB.name TABLENAME, COL.column_id COLUMNID, COL.name FROM sys.tables TAB JOIN SYS.columns COL ON TAB.object_id = COL.object_id WHERE TAB.object_id = 25659888; You need to unpivot the data. Try something like this ;WITH cte AS (SELECT column_name, table_value FROM clients CROSS apply (VALUES ('pk',CONVERT(varchar(20),PK)),

Best practice for SQL Server 2008 schema change

拥有回忆 提交于 2019-12-05 10:23:20
I am looking for information concerning the following: What are the best practices for updating the schema of my dev DB to my production DB, or even more succinctly making DB schema changes in general. The production database is the back-end for two distinct ASP.NET websites. Our schema change process is fairly robust with each "migration" actually being a .cs file containing the schema changes. We will then use ADO.NET to apply the schema changes against the db. My question is more about the connectivity of the database. Should I stop the two websites that are accessing the db. I assume I

Mongoose behavior and schema

有些话、适合烂在心里 提交于 2019-12-05 05:59:11
I am learning nodejs along with mongodb currently, and there are two things that confuse me abit. (1), When a new Schema and model name are used (not in db), the name is changed into its plural form. Example: mongoose.model('person', personSchema); in the database, the table will be called "people" instead. Isn't this easy to confuse new developer, why has they implemented it this way? (2), Second thing is that whenever I want to refer to an existing model in mongoDb (assume that in db, a table called people exists). Then in my nodejs code, I still have to define a Schema in order to create a

How to get columns Primary key constraints using SqlConnection.GetSchema()

这一生的挚爱 提交于 2019-12-05 04:34:47
I have some code of ADO.NET to dynamically detect the database schema, what I need is how to get unique columns constraints and Primary key constraints using the GetSchema method on SqlConnection . This is the code that I have: conn.Open(); SqlCommand mSqlCommand = new SqlCommand("sp_pkeys", conn); mSqlCommand.CommandType = CommandType.StoredProcedure; mSqlCommand.Parameters.Add( "@table_name", SqlDbType.NVarChar).Value = tableName; SqlDataReader mReader = mSqlCommand.ExecuteReader( (CommandBehavior.KeyInfo | CommandBehavior.SchemaOnly)); //ExecuteReader(); DataTable schema = mReader

Storing an Array of Strings in a database

*爱你&永不变心* 提交于 2019-12-05 02:48:28
问题 I have an object that I save to a database through ORM. The object has an array of Strings and the array length can vary per object.I want to know the standard practice for storing the array of String in the db (for example, should I store all the strings in one field as a csv, etc.) ? 回答1: I guess you have a MySql, relational database. As a first approach , you have to think that inserting any kind of composed data (CSV, JSON, serialize() ) in a field in a relational database , is something

Get database schema with one query?

情到浓时终转凉″ 提交于 2019-12-05 02:36:09
Basically I want to get the table names, and the field names for each table from the current database that is connected, nothing else. Is this possible? I know that SHOW TABLES FROM my_database gets you the table names, and SHOW COLUMNS FROM my_table will get you the fields, but that's at least [1 x # of tables] queries and I get more information that I want :) The INFORMATION_SCHEMA.COLUMNS table has what you're asking for. SELECT table_name, column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = 'YourDBName' ORDER BY table_name, ordinal_position SELECT t.name AS tblName, SCHEMA

Create a scalable database schema for storing golf scores

浪子不回头ぞ 提交于 2019-12-05 02:12:42
问题 I am trying to design a database to store all my friends and my golf scores. As you probably know, a golf score is comprised of 18 hole individual scores. I can think of two ways to design the schema: Create a table that has one column for each hole (e.g. h1 to h18), the table has FK player_id, round_id and course_id that referenced other tables. It has a total column, which is the sum of columns h1 to h18. If I change a hole score, I will need to manually update total column. Create a table