UTF-8 nvarchar Romanian letters not displaying in SQL Server 2012 [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a problem with diacritics in my database, it should store words in Romanian. I'm using nvarchar datatype, what should I do?
I have tried this:
INSERT INTO Raion
VALUES
(1,'Chișinău'),
(2,'Bălți'),
(3,'Comrat'),
(4,'Tiraspol')
But I end up with entries like this:
?oldane?ti
?tefan Voda
Anenii Noi
Bal?i
Basarabeasca
Briceni
Cahul
Here's the table:
CREATE TABLE Raion (
id int Primary Key,
denumire nvarchar(255) Not Null Unique
)

Prefix your denumire value with N to indicate a Unicode constant string
Schema
CREATE TABLE Raion
([id] int, [denumire] nvarchar(8))
;
INSERT INTO Raion
([id], [denumire])
VALUES
(1,N'Chișinău'),
(2,N'Bălți'),
(3,N'Comrat'),
(4,N'Tiraspol')
;
Query
SELECT *
FROM raion
Output
id denumire
1 Chișinău
2 Bălți
3 Comrat
4 Tiraspol
SQL Fiddle: http://sqlfiddle.com/#!3/e91d8/1/0

Related

String for inserting data with sub-select into database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm new to C#. I would like to insert data with sub-select into my SQL Server database, I need help to write the string in C# for the following script in SQL Server.
I have two tables, products and category with foreign key between them and a temporary table Mytemp:
CREATE TABLE MyTemp(ID int)
INSERT INTO products (productName, price)
OUTPUT inserted.ID_ProductName
INTO MyTemp
VALUES ('Orange', '2')
INSERT INTO category (ID_productName, Category, Description)
VALUES
((SELECT ID FROM MyTemp), 'Fruits', 'DryFruits');
DROP TABLE MyTemp
You don't need a temp table for this, you can just do it this way:
INSERT INTO products (productName, price)
VALUES ('Orange', '2');
INSERT INTO category (ID_productName, Category, [Description])
VALUES (SCOPE_IDENTITY(), 'Fruits', 'DryFruits');

Storing attendance data in SQL [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Bit of a carry on from this question here: Database design for school attendance system
I am currently doing something similar but have a few additional questions. So the school has approx 200 students but this is constantly changing. They attend for roughly 200 days and its required to keep the attendance data for 7 years. This is my create table statement here:
CREATE TABLE attendance (
studentID INTEGER REFERENCES students (studentID),
date DATE,
present BOOLEAN
);
My question is, is this the best way to create the table?
I haven't really done any direct database stuff from a UI before so my proposed solution was:
First a local variable that would use C# DateTime.Today function to get todays date;
Another local variable which would get the StudentID from the UI;
And then the attendance value which is a boolean, again set by the UI and stored as a 0/1;
All of these then combined into the Insert into SQL statement.
Is this the best way? Any tips or help would be appreciated thanks.
I'd propose this table instead:
CREATE TABLE StudentAttendance (
StudentId int NOT NULL REFERENCES Students (StudentId),
Date date NOT NULL,
PRIMARY KEY( StudentId, Date )
)
I don't feel there is a need for a present column because the presence, or lack of, a row can indicate if a Student was present that day or not.
The table has a composite key comprised of StudentId + Date - this means there cannot be duplicate records (i.e. only 1 row per student per day)
"Id" is an abbreviation for Identity, it is not an initialism so it should not be all-uppercase (i.e. use Id instead of ID).
Update
After having read the comments by other users, especially #JNevill, I recognise that you probably would want to store student absence reasons, which means you will need an IsPresent bit column (as a row could now mean an is-present or is-absent) with a Notes nvarchar(max) column, but we can extend this to a tinyint to store an enum value for different types of attendance records:
enum StudentAttendanceType
{
Present = 0,
UnauthorisedAbsence = 1,
AuthorisedAbsence = 2,
MedicalLeave = 3,
// etc...
}
CREATE TABLE StudentAttendance (
StudentId int NOT NULL REFERENCES Students (StudentId),
Date date NOT NULL,
Type tinyint NOT NULL,
Notes nvarchar(max) NOT NULL
PRIMARY KEY( StudentId, Date )
)

How to write query to insert data in two tables having foreign key relations in SQL Server? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have two tables in SQL Server as:
MobileMaster (MobileId int (PK), MobileName varchar)
and
MobileDetails (MobDetailId int (PK), MobileId int (FK), Color char, Ram int, Camera float)
And I have a Windows form with textboxes for Mobile Name, RAM, Camera, Color.
Now I want to insert the data inserted by user, in these tables in such a way that entry should be done in both tables keeping in mind that MobileID from MobileDetails is a foreign key referencing MobileID in the MobileMaster table, and MobileID and MobDetailsID are kept as Identity (auto-increment).
So help me to do this using SQL Server as database and .net as application development platform. I am not able to write query for it which will be executed when user clicks on the Save button.

How to insert date of dirth directly into my database table [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
My question is there any data type is there in MySQL to insert date of birth into the database table directly else which data type i can choose to insert date of birth into the table?
You're looking for a date, so use the data type DATE
Use the DATE datatype. See here: http://dev.mysql.com/doc/refman/5.1/en/datetime.html the DATE type is distinct from DATETIME in that it ignores the time. You must use the YYYY-MM-DD format in your INSERT OR UPDATE SQL if you're not using parameters (which you should be).
CREATE TABLE People (
dateOfBirth DATE NOT NULL
)
INSERT INTO People ( dateOfBirth ) VALUES ( '1966-07-01' )

how to add instantly made rows key to another table.? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a table named product where there is a field named id its the primary key here. I need to put this key to my another table pro_size_tbl as below
pro_size_tbl
==================
id
productid
sizeid
the matter is when the user adds a product the sizes of the products are saved in session and I am trying to save them in pro_size_tbl by the product key what I just made.
The thing I am doing right now is I am adding the product in the product table and in the next line I am retrieving the max id of the product table and using it as the key for the pro_size_tbl.
My question is is there any better way to do this thing?
This is simple.You can use LAST_INSERT_ID().See this sample:
INSERT INTO table1 (title,userid) VALUES ('test', 1);
SET #last_id_in_table1 = LAST_INSERT_ID();
There is a function LAST_INSERT_ID() which can give you the desired value.
But you need to use right below the insert statement.
owh. from what i understood, u need to put auto generated mysql id to another table?
if so, here is the real deal
$sql_tbl1 = "insert here for first table";
$result_tbl1 = mysql_query($sql_tbl1) or die(mysql_error());
$id = mysql_insert_id();
$sql_tbl2 = "insert here value ($id, 'bla', 'bla')";
mysql_query(sql_tbl2);
LAST_INSERT_ID() function is ok but it is doing the same work as i am doing taking the maximum value.i guess more or less both way are the same.

Categories