Create GUID in Azure Data Factory (Derived Columns) - azure-data-factory-2

I'm wondering if there is a way to generate A GUID with the Expression Builder in ADF.
Something like
Id UNIQUEIDENTIFIER PRIMARY KEY default NEWID()
Hope somebody can help me with this question.
Thanks in advance!
Kind regards
D.

Yes, it has this function named uuid().It will return string value. You can refer to https://learn.microsoft.com/en-us/azure/data-factory/data-flow-expression-functions#uuid.
My test:

Related

Interview: How to handle SQL NOT NULL constraint on the code end

I was recently asked this question in an interview an I'm having trouble formulating the question well enough to find an answer via search engine.
If my SQL database has a NOT NULL constraint placed on the "name" column, how would I be able to create that row, filling it with other data, without tripping the "name" NOT NULL constraint, assuming that you don't have the proper data to insert into the "name" field?
My off the cuff response was to insert an empty string into the "name" field, but I feel like that's too hacky. Does anyone know the proper response?
It's usually a best practice to insert a dummy value such as a -1 that you can easily replace later. A blank string can be more problematic in some cases. To do this you would either use a CASE WHEN statement, or ideally, an ISNULL() function which would look like this ISNULL([ColName], -1) ISNULL is probably the answer they were looking for. That would insert the data if you have it and then if it's null, it would insert a -1.
As Gordon commented, you could also use a DEFAULT value when creating the table. In my answer above, I am assuming you're working with a table that had already been created - meaning you couldn't do that without altering the table.
There are two ways that I can think of for not having to insert name if it is NULL. By far the simpler is to define a default value:
alter table t alter column name varchar(255) not null default '<no name>';
The alternative is to use a trigger, but that is much more cumbersome.
If I were asking a similar question, this is the answer that I would want.
Why bypass the constraint?
In my opinion either your data is wrong or the constraint.
If you bypass constraints, you can't assure some data quality inside the db.
So, i would say the scenario where a table could not be changed even if the constraint is wrong is a huge technical debt which should be solved instead.

Dapper CRUD with GUID Ids

I'm pretty new to Dapper and Dapper.SimpleCRUD (https://github.com/ericdc1/Dapper.SimpleCRUD) so please excuse if I'm being a bit dense. I have an existing database that uses GUID Ids (primary keys) rather than auto incremented int Ids. It seems that Dapper/SimpleCRUD assumes the latter. I guess I may be able to find an alternative (dapper extensions maybe?) but I was wondering if anyone had come across this and adapted it/found some other solution. Dapper Extensions (https://github.com/tmsmith/Dapper-Extensions) also appears to be based on int Ids. Your advice appreciated.
This a clearly a late reply but Dapper.SimpleCRUD now has support for GUID primary keys.
https://www.nuget.org/packages/Dapper.SimpleCRUD

how the db can auto generate uniqueindentifiers?

I have a sql table with id (guid) column.
how can I force the DB to auto generate a new guid for every new record?
Add DEFAULT(newid()).
Using the DEFAULT(newid()) approach, as #SLaks mentioned, you would allow anyone to alter the Guid value from the Guid column, and that could be bad.
One approach to avoid that would be setting the "Guid" Column as a Persisted Computed Column. That way you couldn't even "force" another value onto the Column. But, since the NEWID() function is Non Deterministic, you couldn't define the Computed Column as Persisted, and the whole approach goes down, since not setting is as Persisted would result as a new Guid everytime you Select that row.
That said, I believe you have 2 choices: Stick with the DEFAULT(newid()) approach or work with Triggers for that.
Please try using the following query:
CREATE TABLE TEST
(
ID UNIQUEIDENTIFIER DEFAULT NEWSEQUENTIALID() PRIMARY KEY,
TESTCOLUMN CHAR(2000) DEFAULT REPLICATE('X',2000)
)
GO

What does this mean -> "Specify the SQL statement that would define the table, AND maintain referential integrity?"

Just looking through some past papers prior to my SQL exam and came across this gem, can someone please explain what is being asked here as it is confusing me. I don't really understand what is being asked, and what is meant by "specify the SQL statement that would define the table".
I understand referential integrity, I believe. It just means that if a value is stored in one table and then referenced in another, they must be the same.
How does that apply to this question ?
Thanks a lot :)
The question is asking you to write a CREATE TABLE statement with the appropriate constraints to maintain RI against some set of foreign keys. Since you haven't provided the complete question it's hard to know exactly what is wanted.
I would imagine they want some DDL that includes a foreign key definition. e.g. something like
CREATE TABLE YourTable
(
bar int not null primary key,
foo int not null references othertable(foo)
)

Fluent-NHibernate table mapping with no primary key

I am trying to create a mapping to a database table that has no primary keys/references.
public class TestMap : ClassMap<<Test>Test> {
public TestMap() {
WithTable("TestTable");
Map(x => x.TestColumn);
}
}
This fails and expects id or composite-id. Is this possible in fluent nhibernate?
In Oracle at least, I have used "ROWID" for this. For mssql you might use the "ROW_NUMBER()" builtin function for readonly access to the table, but I haven't tried that...
No. You'll have to add a surrogate primary key, such as an identity column in SQL Server, to map this table. As far as I know, this isn't supported by NHibernate itself.
Why don't you have a primary key on this table?
This functionality isn't supported by nhibernate as far as I know. As a general rule of thumb, however, you should really always have some kind of ID and if you find yourself in a situation where you think you don't need one you should assess your data model. An ID, whether it be a table-specific primary key, or a surrogate key from another table, should exist. This not only ensures that nhibernate can process the table, but helps performance via indexing.
Before you start assuming nhibernate isn't going to fulfill your needs, consider why you don't have a key on the table and what kind of sense it makes not to have one.
If we can bring a column from table having no primary key/identity coulmn, then we can use fluent as below:
Id(x => x.TempID).Column("TempID");
If the table contains data that belongs to another entity, you could map it as a collection of components. Components are not identified by themselves, but they belong to another entity, which is identified.
You can map an entity to a table without keys defined in the database. I do so in legacy SQL Server databases. However, the table must have a candidate key (some set of columns that actually stores a unique combination of values). The concept of entity involves the notion of some kind of identity.
Instead of this, what you're trying in your code is to map an entity without identity, wich isn't possible.