Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8933565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:34:12+00:00 2026-06-15T09:34:12+00:00

how to create Primary key with a specific name when creating the table itself.

  • 0

how to create Primary key with a specific name when creating the table itself.

I wanted to know if we can create Primary Key as part of the table name as well, and also give it a name at the same time. Though it would look very normal to all experienced developers, it can be still confusing to many.

What am I doing wrong?

CREATE TABLE [dbo].[TestTable](
[ID] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](100) NULL)
GO
ALTER TABLE [dbo].[TestTable] ADD CONSTRAINT [PK_TestTable] PRIMARY KEY CLUSTERED
([ID] ASC)
GO

Thanks,Mahendra

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:34:13+00:00Added an answer on June 15, 2026 at 9:34 am

    foreach enumerates any object that implements IEnumerable, IEnumerable<T>, IEnumerator, or IEnumerator<T> (or actually any object whose class implements a compatible Current property and MoveNext() method). The syntax for foreach is:

    foreach (type variable in enumerable) { ... }
    

    type is the type of the new variable variable. (If you already have an existing variable to use then omit the type.)

    The body of the loop will be executed for each object in the enumerable, and the iteration variable (here variable) will contain the object on each iteration.

    for is much more general-purpose, and follows this pattern:

    for (initial-statements; loop-condition; post-iteration-actions) {
        body
    }
    

    Which is almost exactly equivalent to:

    initial-statements
    while (loop-condition) {
        body
        post-iteration-actions
    }
    

    You may see a for loop when dealing with arrays, for example:

    for (int index = 0; index < array.Length; index++) {
        Console.WriteLine(array[index]);
    }
    

    This is the same thing as:

    {
        int index = 0;
        while (index < array.Length) {
            Console.WriteLine(array[index]);
            index++;
        }
    }
    

    (Note that using foreach over arrays is optimized by the compiler to use a similar index-based iteration, since this is faster. So all three approaches should have equivalent performance and runtime semantics when enumerating an array.)


    Further information, if you want it:

    foreach is actually just syntactic sugar, and can be easily translated into a while loop.

    foreach (object x in y) {
        Console.WriteLine(x);
    }
    

    This actually means:

    var enumerator = y.GetEnumerator();
    try {
        object x; // See footnote 1
        while (enumerator.MoveNext()) {
            x = enumerator.Current;
            Console.WriteLine(x);
        }
    } finally {
        ((IDisposable)enumerator).Dispose();
    }
    

    Except that the enumerator variable has no name and is hidden from you.

    It’s pretty obvious why foreach exists. Everywhere you use it today you would otherwise have to write this horribly verbose boilerplate code. foreach takes care of everything for you — grabbing an enumerator, testing MoveNext() on each iteration, extracting the enumerator’s current value, and disposing of the enumerator after iteration completes.

    1 This variable is actually semantically declared inside of the loop, starting with C# 5. This example is accurate for C# 4 and predecessors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

create table ImagenesUsuario { idImagen int primary key not null IDENTITY } This doesn't
CREATE TABLE Posts { id INT PRIMARY KEY AUTO_INCREMENT, title VARCHAR(200), url VARCHAR(200) }
CREATE TABLE SupplierQuote ( supplierQuoteID int identity (3504,2) CONSTRAINT supquoteid_pk PRIMARY KEY, PONumber int
CREATE TABLE `db`.`Complete` ( `CompleteId` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
There is a table: create table table1 ( id integer primary key, user_id varchar(36),
I have just created this table: create table dbo.OrderTypes ( ID smallint primary key
Is there a way to set the PRIMARY KEY in a single CREATE TABLE
With the following DB schema: CREATE TABLE master ( id integer primary key autoincrement,
Consider the following tables: CREATE TABLE user_roles( pkey SERIAL PRIMARY KEY, bit_id BIGINT NOT
Why would we create a sequence even if there is a primary key?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.