primary-key

How to change the column length of a primary key in SQL Server?

☆樱花仙子☆ 提交于 2021-02-08 12:19:35
问题 I know how to change the length of a column, but my SQL statement fails because the column I'm trying to change is a PK, so I get the following error: Msg 5074, Level 16, State 1, Line 1 The object 'PK_TableName' is dependent on column 'PersonID'. PersonID = PK. I've read What is the sql to change the field length of a table column in sql server which only applies to non-PK columns. I tried this: ALTER TABLE table_name ALTER COLUMN column_name <new datatype> 回答1: See below sample example how

How to change the column length of a primary key in SQL Server?

99封情书 提交于 2021-02-08 12:17:58
问题 I know how to change the length of a column, but my SQL statement fails because the column I'm trying to change is a PK, so I get the following error: Msg 5074, Level 16, State 1, Line 1 The object 'PK_TableName' is dependent on column 'PersonID'. PersonID = PK. I've read What is the sql to change the field length of a table column in sql server which only applies to non-PK columns. I tried this: ALTER TABLE table_name ALTER COLUMN column_name <new datatype> 回答1: See below sample example how

Does MySQL create an extra index for primary key or uses the data itself as an “index”

微笑、不失礼 提交于 2021-02-07 22:47:43
问题 Cant find a explicit answer of that. I know that when you create a primary key, MySQL orders the data according to that primary key, question is, does it actually create another index, or uses the actual data as an index since it should be ordered by the primary key? EDIT: if I have a table with has index A and index B and no primary key, I have the data + index A + index B. If I change the table to have columns of index A as the primary key, I will only have data (which is also used as an

primary key is always indexed in sql server?

最后都变了- 提交于 2021-02-07 13:15:54
问题 You can create a clustered index on a column other than primary key column if a nonclustered primary key constraint was specified. http://msdn.microsoft.com/en-us/library/ms186342.aspx So the above told me: I can create a clustered index on columns other than primary key. I think it also conveys that a primary key should either be a nonclustered primary key or clustered key. Is it possible a primary key is not indexed? What's more: When you create a UNIQUE constraint, a unique nonclustered

Oracle - return newly inserted key value

雨燕双飞 提交于 2021-02-07 05:43:21
问题 We have a table with a Primary Key that gets populated on insert by a trigger on the table - the trigger gets the next sequence number from a sequence we created for the table and uses that for the value of the key on insert. Now we would like to be able to return that value in our insert procedure (PL\SQL), similar to select @@scope_identity in SQL Server. I have been googling all day and basically come up with nothing - anyone been successful with this before? Thanks 回答1: I don't know if it

mysql changing unique key to primary (mariadb)

元气小坏坏 提交于 2021-02-04 21:37:17
问题 I have my table users: +--------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------------+--------------+------+-----+---------+-------+ | userid | varchar(30) | YES | | NULL | | | lname | varchar(40) | YES | | NULL | | | fname | varchar(20) | YES | | NULL | | | system_id | varchar(12) | YES | | NULL | | +--------------------+--------------+------+-----+---------+-------+ and I want to change the system_id and the userid

How to generate/autoincrement guid on insert without triggers and manual inserts in mysql?

冷暖自知 提交于 2021-02-04 20:56:05
问题 Im revisiting my database and noticed I had some primary keys that were of type INT. This wasn't unique enough so I thought I would have a guid. I come from a microsoft sql background and in the ssms you can choose type to "uniqeidentifier" and auto increment it. In mysql however Ive found that you have to make triggers that execute on insert for the tables you want to generate a guide id for. Example: Table: CREATE TABLE `tbl_test` ( `GUID` char(40) NOT NULL, `Name` varchar(50) NOT NULL,

What is a PRIMARY KEY

妖精的绣舞 提交于 2021-02-04 19:17:05
问题 In database code I see references to a PRIMARY KEY . What is a PRIMARY KEY, and what difference does it make if some of the columns in one of my tables form a PRIMARY KEY... or don't form a PRIMARY KEY. (Amazingly, this question does not seem to have been asked before on SO) 回答1: 1st Normal Form requires that you have a unique key for you to have a relation. If this requirement is not met (i.e. if you have no unique keys), then your table will be just a heap, not a relation. The primary key

Entity Framework primary key constraint

风流意气都作罢 提交于 2021-01-29 18:42:28
问题 I am using Entity Framework 6.0 with Microsoft SQL Server. By default, the primary key it generates for a table is named like PK_dbo.TableName , where TableName is in a plural form, even though the actual name of the table is in a singular form. For example, I have a table named dbo.Employee . Yet the primary key denoted by EF 6 is PK_dbo.Employees . Is there any way to change the primary key to something like PK_TableName where the TableName is in a singular form? Update: Thanks for the

Entity Framework primary key constraint

左心房为你撑大大i 提交于 2021-01-29 12:44:45
问题 I am using Entity Framework 6.0 with Microsoft SQL Server. By default, the primary key it generates for a table is named like PK_dbo.TableName , where TableName is in a plural form, even though the actual name of the table is in a singular form. For example, I have a table named dbo.Employee . Yet the primary key denoted by EF 6 is PK_dbo.Employees . Is there any way to change the primary key to something like PK_TableName where the TableName is in a singular form? Update: Thanks for the